Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully Closing a Redis Connection: Best Practices? #605

Closed
Makhlab opened this issue May 31, 2024 · 1 comment
Closed

Gracefully Closing a Redis Connection: Best Practices? #605

Makhlab opened this issue May 31, 2024 · 1 comment

Comments

@Makhlab
Copy link

Makhlab commented May 31, 2024

I can't find a way to close the connection using @tirke/node-cache-manager-ioredis, either in the cache manager or the store implementation. Does anyone have insights on how to call redis.disconnect() or redis.quit()?

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  TCPWRAP

      33 |   public static async getInstance(): Promise<ICacheService> {
      34 |     if (!RedisStoreProvider.instance) {
    > 35 |       const cache: Cache = await caching(ioRedisStore, redisConfig);
         |                                         ^
      36 |       cache.on('error', (error: unknown) => {
      37 |         logError('Redis store error', error);
      38 |       });

      at node_modules/ioredis/built/connectors/StandaloneConnector.js:44:21
      at StandaloneConnector.connect (node_modules/ioredis/built/connectors/StandaloneConnector.js:43:16)
      at node_modules/ioredis/built/Redis.js:121:64
      at EventEmitter.connect (node_modules/ioredis/built/Redis.js:103:25)
      at new Redis (node_modules/ioredis/built/Redis.js:77:18)
      at new RedisStore (node_modules/@tirke/node-cache-manager-ioredis/index.js:57:21)
      at ioRedisStore (node_modules/@tirke/node-cache-manager-ioredis/index.js:124:10)
      at caching (node_modules/cache-manager/dist/caching.js:19:29)
@Makhlab Makhlab changed the title How to close Redis connection gracefully? Gracefully Closing a Redis Connection: Best Practices? Jun 1, 2024
@Tirke
Copy link
Owner

Tirke commented Jun 3, 2024

Hello @Makhlab in your example you can access the underlying redis client at cache.store.client.
Disconnecting manually is accessible through cache.store.client.disconnect()

@Tirke Tirke closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants