Script to ping Redis and if no response restart redis

185 views
Skip to first unread message

Peter Cowen

unread,
Sep 12, 2018, 4:37:12 AM9/12/18
to Redis DB
Hi There,

Is there a way to create a script where it runs the redis-cli ping command and if no response is given or an error is shown it restarts redis. I have logstash on the same server where I can perform a redis-cli ping but it just puts the output into elasticsearch.

Is it also possible to query the list of clients connected to redis and if logstash is not connected restart logstash.


Itamar Haber

unread,
Sep 12, 2018, 8:53:45 AM9/12/18
to Redis DB
Hello Peter,

I'm pretty sure you can do that with any scripting language, and you even have Redis clients (https://redis.io/clients) for most so you don't have to depend on the cli.

I'm also pretty sure that most generic watchdogs can be used to restart fallen services.

You can get the list of connected clients with the `CLIENT LIST` command - https://redis.io/commands/client-list

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber
Technicalist Evangenly

Phone: +972.54.567.9692

Redis Labs


hva...@gmail.com

unread,
Sep 12, 2018, 11:33:53 AM9/12/18
to Redis DB
Be careful automating the start of a long-running daemon/service like Redis:
  1. When it stops unexpectedly, it's usually for a reason that won't go away, so your automation will get into a loop of constant start, crash, start, crash, start, crash, ...
  2. When you stop Redis deliberately so you can test or investigate something, your automation will start it up again, against your will, and often without your knowledge - ruining your test/investigation.
These are common situations that you need to handle properly in your automation to restart Redis (or any other daemon/service).

Another negative aspect of automated restarts is they tend to hide the causes of crashes, so the causes go longer without being fixed.  You think your Redis is doing fine, then a customer reports that for weeks they've been getting error responses 15% of the time.

Peter Cowen

unread,
Sep 14, 2018, 4:33:03 AM9/14/18
to Redis DB
Thank you for the considerations. We currently use Redis as a buffer between our logs and logstash to stop logstash from being overloaded. Are we better off looking to see if we can add something at the log side to check if redis is up first and if it isn't use a different method?

Tuco

unread,
Sep 15, 2018, 1:59:53 AM9/15/18
to Redis DB
Another idea is to have a shell script on the redis server, which checks whether the redis-server process is running using ps -ef command, if it is not, it should send an email and start redis. That's the script we have.

If you start to ping and start redis, you run the risk of giving client the ability to start or stop redis (which should be avoided).
Also, it is possible that a slow command was blocking redis, so that your ping couldn't get through, but your redis was up, so that your script will think that the redis is down, when that was not the case.

Reply all
Reply to author
Forward
0 new messages