Skip to content

Commit

Permalink
fix: Add two Redis instance options, one when a URL exists and one wh…
Browse files Browse the repository at this point in the history
…en it doesn't
  • Loading branch information
juandav committed Dec 22, 2023
1 parent ad220d7 commit f5d1819
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/redis.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Redis from 'ioredis';
import { RedisModuleOptions, RedisOptions } from './redis.interfaces';
import Redis, { RedisOptions } from 'ioredis';
import { RedisModuleOptions } from './redis.interfaces';
import {
REDIS_MODULE_CONNECTION,
REDIS_MODULE_CONNECTION_TOKEN,
Expand All @@ -21,10 +21,13 @@ export function createRedisConnection(options: RedisModuleOptions) {
case 'cluster':
return new Redis.Cluster(options.nodes, commonOptions);
case 'single':
const { url, port, host } = options;
const connectionOptions: RedisOptions = { ...commonOptions, url, port, host };
return new Redis(connectionOptions);
const { url, options: { port, host } } = options;
const connectionOptions: RedisOptions = { ...commonOptions, port, host };

return url ? new Redis(url, connectionOptions) : new Redis(connectionOptions);
default:
throw new Error('Invalid configuration');
}
}


0 comments on commit f5d1819

Please sign in to comment.