Ping command in ioredis-Node JS
Asked Answered
C

1

6

Is there any way to check weather redis is available or terminated due to some issues before I am setting or getting a key ? How can I achieve that?

I am using ioredis module.

Carrie answered 25/1, 2016 at 9:50 Comment(0)
G
10
 var Redis = require('ioredis');
 var redis = new Redis();


 var test = redis.ping(function (err, result) {
     console.log(result);
 });

The result should be the word PONG if no paramters are passed and Redis is working.

PONG: This command is often used to test if a connection is still alive, or to measure latency.

Gallinacean answered 25/1, 2016 at 20:5 Comment(2)
I am not getting response back if the redis is unavailable, I am getting PONG after redis got up, Is there any way to get immediate response for PING command.Carrie
ioredis will try to reconnect to the Redis server when it's unavailable. Disalbe retryStrategy and you'll get the response immediately.Tricrotic

© 2022 - 2024 — McMap. All rights reserved.