skip to Main Content

I am using redis as a cache in one of my spring boot java application. I am performing only get operation on this redis instance from a scheduler code which runs every 30 seconds and write operation is performed by some other application. I have a scenario where if my redis instance goes down due to any reason then I have to stop doing a particular action. I am using jedis as redis client.
Assume my jedis pool was configured and connection pool was created successfully.

For couple of iterations my scheduler worked fine and was able to perform the get operation on redis.
Now assume redis went down so now at this point after 30 seconds my scheduler will run again and it will fail to perform get operation.
I just need to identify if redis went down at this point.
Is there any way to identify if the redis went down in above mentioned scenario?

2

Answers


  1. Chosen as BEST ANSWER

    It took me sometime to figure out as I am new to redis but I found a simple way by catching the JedisConnectionException as this exception is thrown when redis server is down. Posting the answer if someone might face this scenario.


  2. Connect to redis server via Jedis client and run info command to get more information:

        try (Jedis jedis = new Jedis("localhost", 6379)) {
            String result = new String((byte[]) jedis.sendCommand(Protocol.Command.INFO));
        ... 
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search