nest-modules / ioredis

:see_no_evil: :hear_no_evil: :speak_no_evil: A ioredis module for Nest framework (node.js)
MIT License
145 stars 31 forks source link

Can you provide support for Redis Cluster? #275

Closed a1enc closed 10 months ago

a1enc commented 10 months ago

Can you provide support for Redis Cluster?

If you just modify the createRedisConnection function, it seems to work normally.

I am using it by modifying the module as follows:

export interface RedisModuleOptions {
  config?: RedisOptions & { url?: string };

  port?: number;
  host?: string;
  url?: string;
  nodes?: ClusterNode[];
  options?: RedisOptions | ClusterOptions;
}
export function createRedisConnection({ config, ...redisOptions }: RedisModuleOptions) {
  if (config) {
    if (config.url) {
      redisOptions.url ||= config.url;
    }
    redisOptions.options ||= { ...config };
  }

  const { port, host, url, nodes, options } = redisOptions;

  if (nodes) {
    return new Redis.Cluster(nodes, options);
  } else if (url) {
    return new Redis(url, options);
  } else if (port && host) {
    return new Redis(port, host, options);
  } else if (port) {
    return new Redis(port, options);
  } else if (options) {
    return new Redis(options);
  }
  throw new Error('Invalid configuration');
}

Thanks

juandav commented 10 months ago

Yes, I will be working on it.

a1enc commented 10 months ago

Thanks

juandav commented 10 months ago

I have added support for clusters in version 2.0.0; for now, I have published it, but I am currently conducting several tests.

a1enc commented 10 months ago

Thank you very much for your quick processing.