Nest: CacheModule kills app if theres no redis connection

Created on 1 May 2019  路  8Comments  路  Source: nestjs/nest

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently when i'm using CacheModule.register and redis connection fails, the server exits with an error:

Error: Redis connection to redis:6379 failed - getaddrinfo ENOTFOUND redis redis:6379
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)

Expected behavior

Handle the error to just log the error and not break the entire app, maybe add a retry exponentially.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: 5.4.0


For Tooling issues:
- Node version: v10.6.0  
- Platform: Mac 

Others:

needs clarification common

All 8 comments

Please, provide a minimal repository which reproduces your issue.

@kamilmysliwiec
https://github.com/yogevlahyani/nestjs-redis-cache-example

Basically, I don't want the process to exit with error, just log that the redis is unable to connect or something

You need to inject the exposed CACHE_MANAGER in the module constructor to get your hands on the redis client:

import { CACHE_MANAGER, Inject } from '@nestjs/common';

...

export class AppModule {
    constructor(@Inject(CACHE_MANAGER) cacheManager) {
        const client = cacheManager.store.getClient();

        client.on('error', (error) => {
            console.error(error);
        });
    }
}

@atte-backman I tried it but inside a service, seems that inside the AppModule it doesn't breaks the app,
Thanks!! :100:

I think we should keep this opened to solve this problem out-of-the-box

@kamilmysliwiec Agreed! 馃

Oh I missed one thing :( It actually should be fixed here https://github.com/dabroek/node-cache-manager-redis-store We don't provide this store out-of-the-box, my mistake!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

VRspace4 picture VRspace4  路  3Comments

rafal-rudnicki picture rafal-rudnicki  路  3Comments

FranciZ picture FranciZ  路  3Comments

KamGor picture KamGor  路  3Comments

marshall007 picture marshall007  路  3Comments