Redis client created with CacheManager (still) does not close when app quits
See original GitHub issueBug Report
Current behavior
This is effectively a repeat of https://github.com/nestjs/nest/issues/1621
This problem resurfaced with the 3.x release of nestjs-command
https://www.npmjs.com/package/nestjs-command, which removed the { autoExit }
option. Redis is still running, and prevents CLI commands from wrapping up.
Input Code
I have a sample repo if that would be helpful.
Possible Solution
@kamilmysliwiec advised “I’d suggest triggering close in the onModuleDestroy()”. I cannot figure out how to reach Redis directly via the cache manager service (also I’m unclear if he even means triggering “close” on Redis, or on a wrapping module, or…?)
I will be happy to update the documentation and post a PR upon solving this issue.
Environment
Nest version: 8.0.6
For Tooling issues:
- Node version: 16.4.0
- Platform: Mac
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Redis client created with CacheManager does not close when ...
When the nest application quits, it doesn't close the redis client. Expected behavior. When app.quit() it should trigger the CacheModule to ...
Read more >What if Redis Stops Working - How Do I Keep My App Running
The original intent of the reported issue was, that the user wanted to temporarily disable the Redis cache layer while the Redis server...
Read more >Handling Nest.js app on Redis cache store disconnection
I need to inject the exposed CACHE_MANAGER in the module constructor to get my hands on the client: import { CACHE_MANAGER, Inject }...
Read more >Client-side caching in Redis
Client -side caching is a technique used to create high performance services. It exploits the memory available on application servers, servers that are...
Read more >Could not connect to redis connection refused - Fix it easily
The most common reason for the connection refused error is that the Redis-Server is not started. Redis server should be started to use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
jinx!
Pretty much! I’m going to close this out as it seems there isn’t anything to do on the Nest side of things.
One other option would be to create your own redis provider connection and more easily close that with proper intellisense. Then when that closes the cache-manager shouldn’t stay open on close. I’ll be happy to discuss that approach in our Discord if you’re interested