node.js中redis使用有什么坑,怎么做好
Admin 2022-08-17 群英技术资讯 409 次浏览
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});
问题解决,我厂真是坑多呀!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
日常开发中写的 JavaScript 代码,会用到ES6的部分新特性,所以下面这篇文章主要给大家介绍了关于ES6新特性最常用的知识点,文章总结的非常全面,需要的朋友可以参考下
这篇文章我们主要了解关于vue中router传参方式,本文有示例代码供大家参考,感兴趣的朋友可以了解看看,另外本文还分享了刷新页面数据丢失的解决方法,接下来我们一起了解看看吧。
用JavaScript写一个九宫格的抽奖盘,供大家参考,具体内容如下点击中间的块,选中奖品的亮块会在边缘的8个块循环;选中后,弹出选中的内容;代码参考:HTML文件:bodydiv class=box ul id=jiangPin lia href=javascript:viod(0); span奖
这篇文章主要给大家介绍了关于require加载器实现原理的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
我们平常在浏览一些网站的时候,经常能看到选项卡展示功能,其好处就是节约页面空间,我们只要点击不同的区域,就能展现不同的内容,这样能比较合理的展示内容。那么JS是怎样实现选项卡插件的呢?
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008