7

I'm writing a nodejs 5.10.1 application, and i connect to a redis-server.

i'm using the ioredis nodejs module from https://github.com/luin/ioredis.

I can't seem to figure out how to check if a connection was established to the server.

the code to connect to a redis server is pretty simple:

var Redis = require('ioredis');
var redis = new Redis();

the documentation states the following under Connection Events

You can also check out the Redis#status property to get the current connection status.

don't really understand what it means or how to work with it. any ideas ?

ufk
  • 30,912
  • 70
  • 235
  • 386

1 Answers1

20

One of the properties of the redis object you started is the status:

console.log(redis.status) will give you the current , in my case it says : connecting

Rabea
  • 1,938
  • 17
  • 26
  • 2
    I dont think status is giving correct result. I tried with random IP; it failed to connect but status is still showing connecting – dd619 Jan 02 '23 at 10:38