nodejs redis遇到的一个问题解决

var redis = require("redis"),
    client = redis.createClient({host:'tc-arch-osp33.tc', port: 4300,no_ready_check:true});



// if you'd like to select database 3, instead of 0 (default), call 
// client.select(3, function() { /* ... */ }); 

client.on("error", function (err) {
                console.log("Error " + err);
                });
client.on("connect", function (err) {
                console.log("success" + err);
                client.set("stringkey", "string val",function (err1, re1){
                        console.log(err1);
                        console.log(re1);

                        });;

上面的代码连接公司的redis会出现以下现象:

successundefined
Error AbortError: Ready check failed: Redis connection lost and command aborted. It might have been processed.
successundefined
Error AbortError: Ready check failed: Redis connection lost and command aborted. It might have been processed.
successundefined
//如此反复出现

但通过命令行redis-cli可以正常连接并操作redis。

到此反复试验N次,花费很久。

抓包看看,结果如下:

可以看到nodejs不断发起针对 redis server的链接,redis server不断的关闭,如此反复,跟前端的日志输出也是对应的。

细看其中一个包:

貌似看到nodejs发了一个未知的命令给redis server,经过询问我司的redis维护人员,说是不支持info命令。。。。

至此真想大白

再查nodejs redis文档,有一条:

no_ready_checkfalseWhen a connection is established to the Redis server, the server might still be loading the database from disk. While loading, the server will not respond to any commands. To work around this, node_redis has a "ready check" which sends the INFO command to the server. The response from the INFO command indicates whether the server is ready for more commands. When ready, node_redis emits a ready event. Setting no_ready_check to true will inhibit this check.

所以给我们的代码加一个参数即可,如下:

no_ready_check:true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值