Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set a timeout for redis-cli command?

I have a health check I'm trying to use that executes the redis-cli command from the redis servers to the redis-sentinels remotely.

redis-cli -h 10.10.10.10 -p 26379 SENTINEL MASTER testing

There is a logic that sorts out whether there is a quorum and it all works fine unless a sentinel's network interface is unavailable. The redis-cli command hangs indefinitely in this case and the health check fails even though there are two healthy sentinels with a quorum.

I can't seem to find a way to set a timeout for the redis-cli on the client side to prevent it from hanging. Is there a way with redis-cli to do this or will I have to go outside the command to ensure it doesn't hang indefinitely?

like image 413
numb3rs1x Avatar asked Jul 07 '16 19:07

numb3rs1x


People also ask

How do I set timeout in Redis?

To create a Redis with an expiration time, use the SET command and the EX option to set the expiration time. The EX option takes a number in seconds and sets the number of seconds the key is valid until expiration. You can also use PX to specify the expiration time in Milliseconds.

What is connection timeout in Redis?

The maximum length of time to wait while establishing a connection to a Redis server.

How set Redis connection limit?

In the Redis config file (redis. conf), there's maxclients, a property describing the maximum number of clients that can connect to Redis server. You can also set the maximum number of clients you want to connect to Redis by passing two options like this: redis-server—maxclients 100000.

Can we set TTL in Redis?

Redis TTL command is used to get the remaining time of key expiry in seconds. Returns the remaining time to live of a key that has a timeout. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset.


1 Answers

I decided to use the timeout command to wrap the redis-cli command. It seems to work very well for my purposes!

timeout 3 redis-cli -h 10.10.10.10 -p 26379 SENTINEL MASTER testing
like image 129
numb3rs1x Avatar answered Nov 28 '22 01:11

numb3rs1x