Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to kill idle clients opened by Node on Redis?

I'm having a very difficult time to automatically close Redis' client connections. It is most certainly a problem with the redis package:

(https://www.npmjs.com/package/redis)

Redis will keep connections alive until you close them or a timeout, that defaults to infinite, is reached.

I'm aware of this:

how do I kill idle redis clients

And even before reading on SO I tried to set the timeout config both by .conf file and by command line but none of them worked.

What actually happens is very weird:

If I run CLIENT LIST after the N seconds:

  • The same number of idle connections are still there
  • The client 'idle' info restarts from 0 (for example, if I set 10 seconds of timeout, after 11 seconds the idle info is 1).
  • The addr changes. The port number changes as it is creating new connections to not lose that client.
  • The client is actually attached to Node. It seems to be a new node process. If I keep the node app UP the connections won't die. If I close the app all connections created by it close. So redis module is probably 'restarting' the connection.

Any ideas on what I should do not force the 'resurection' of a killed client?

Obs: I understand I can close the client's connection with 'quit()', but I must assure it will get rid of any idle client that wasn't closed by the application after some time.

like image 891
Victor Ferreira Avatar asked Nov 25 '25 22:11

Victor Ferreira


1 Answers

To prevent node redis from reconnecting, I passed to createClient the key retry_strategy.

it must be a function that retuns false or throws an Error

like image 132
Victor Ferreira Avatar answered Nov 27 '25 14:11

Victor Ferreira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!