作者:手机用户2502941011 | 来源:互联网 | 2023-09-02 18:32
varredisrequire("redis"),clientredis.createClient({host:tc-arch-
v
ar 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);
});;
上面的代码连接我厂(baidu)提供的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_check |
false |
When 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
client = redis.createClient({host:'tc-arch-osp33.tc', port: 4300,no_ready_check:true});
问题解决,我厂真是坑多呀!