如果与 redis 服务器建立了连接,如何检查 ioredis?

how to check with ioredis if the a connection was established to the redis server?

我正在编写一个 nodejs 5.10.1 应用程序,并且我连接到一个 redis 服务器。

我正在使用 https://github.com/luin/ioredis 的 ioredis nodejs 模块。

我似乎不知道如何检查是否已与服务器建立连接。

连接到 redis 服务器的代码非常简单:

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

文档在连接事件下说明如下

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

不太了解它的含义或如何使用它。有什么想法吗?

您启动的 redis 对象的属性之一是 status:

console.log(redis.status) 会给你电流,在我的情况下它说:connecting