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});
問題解決,我廠真是坑多呀!
