node.js中redis使用有什么坑,怎么做好
Admin 2022-08-17 群英技术资讯 542 次浏览
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实现随机抽奖功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了uni-app 的基础组件,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
Vue实现PC端靠边悬浮球的代码,我想把退出登录的按钮做成一个悬浮球的样子,带动画的那种。
这篇文章我们来了解jQuery修改行内样式的方法,改变行内样式并不难,这里我们使用attr()就能实现,下面我们通过实例来详细的了解看看吧,有需要的朋友可以参考。
这篇文章主要给大家分享了 v-bind的使用和注意需要注意的点,下面文章围绕 v-bind指令的相关资料展开内容且附上详细代码 需要的小伙伴可以参考一下,希望对大家有所帮助
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008