node.js中redis使用有什么坑,怎么做好
Admin 2022-08-17 群英技术资讯 946 次浏览
这篇文章主要介绍“node.js中redis使用有什么坑,怎么做好”的相关知识,下面会通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“node.js中redis使用有什么坑,怎么做好”文章能帮助大家解决问题。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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
最近再做个项目,需要检查token过期,跳转到登录页面,要求用户重新登录,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了vue3+typeScript穿梭框的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
篇文章介绍的是React嵌套组件构建顺序的问题,究竟在嵌套组件中,是父组件先构建,还是子组件先构建?是子组件先更新,还是父组件先更新呢?接下来小编就与大家一起来探讨一下。
JavaScript实现鼠标移动事件画笔 JavaScript实现鼠标移动事件画笔小游戏,供大家参考,具体内容如下 实现功能 鼠标点击时可以在画板上画画如果鼠标双击那么停止移动进画板颜色改变移除时颜色改变 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content=" ...
前言用Vue3实现一个简易的音乐播放器组件其效果图如下所示:实现这个组件需要提前做的准备:引入ElementUI引入字节跳动图标库一张唱见图片将要播放的音乐上传到文件服务器上,并提供一个能在线访问的链接【这里使用的是阿里云的OSS服务】准备ElementUIElementUI的引入可以参照其官网的引入方式;字节跳动图标
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008