node.js中redis使用有什么坑,怎么做好
Admin 2022-08-17 群英技术资讯 843 次浏览
这篇文章主要介绍“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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
jquery.md5有什么用jQuery md5加密插件jQuery.md5.js用法有时候我们想在js里面使用加密,jQuery就提供了这样的插件,用法十分简单使用方法:<div class="jb51code">rush:Js;">$.(
什么是Puppeteer库?能做什么?怎么使用?下面本篇文章就来给大家介绍一下Puppeteer库,了解一下Node.js中使用Puppeteer库的方法,希望对大家有所帮助!
在本篇文章里小编给大家整理了一篇关于js数组forEach实例用法详解内容,有需要的朋友们可以跟着学习参考下。
怎么利用node生成word文档?下面本篇文章给大家介绍一下使用node生成word文档的方法,分享一个实用库,聊聊该库的使用方法,希望对大家有所帮助!
目录我使用的命令是 vue ui 可视化打包操作进入可视化面板需要通过vue.config.js来配置.js文件中,导致该js文件过大通常在一个vue项目中会用到很多插件什么,swiper,axios,vuerouter,vuex,…,那么使用了很多插件势必会造成打包的js文件过大,影响加载速度,造成不好的用户体验,那
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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