Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何重新连接redis连接?_Node.js - Fatal编程技术网

Node.js 如何重新连接redis连接?

Node.js 如何重新连接redis连接?,node.js,Node.js,我举一个简单的例子: var redis = require('redis'), client = redis.createClient(); var test = function() { client.brpop('log', 0, function(err, reply) { if (err != null ) { console.log(err); } else { .... parse lo

我举一个简单的例子:

var redis = require('redis'),
client = redis.createClient();

var test = function() {
    client.brpop('log', 0, function(err, reply) {
        if (err != null ) {
            console.log(err);
        }    else {
            .... parse log string ....
        }
        test();
    });
}

test();

重新启动redis服务器后如何重新连接redis连接?

redis客户端自动重新连接。只需确保处理来自客户端的
“error”
事件。根据:

否则,这就是过程的开始

this.emit("error", new Error(message));
// "error" events get turned into exceptions if they aren't listened for.  If the user handled this error
// then we should try to reconnect.
this.connection_gone("error");
接下来,该方法在客户机上运行

请注意,您还可以侦听发生此情况时要通知的
“重新连接”
事件

this.emit("error", new Error(message));
// "error" events get turned into exceptions if they aren't listened for.  If the user handled this error
// then we should try to reconnect.
this.connection_gone("error");