tendis nodejs 连接问题

经过测试node-redis 客户端与tendis 连接是有点问题的(golang 以及java 是没有问题的)

原因分析

因为node-redis 支持debug模式,通过分析发现还是tendis兼容的问题与redis还是有差异的

  • 具体分析方法
    参考代码
 
const redis = require("redis");
const client = redis.createClient({
  port:51002,
  host:"localhost",
  password:"test"
});
client.on("error", function(error) {
 // console.error(error);
});
 
client.on("ready",function(data){
 // console.log("ready",data)
})
 
client.on("connect",function(data){
  console.log("connect",data)
})
 
client.on("warning",function(data){
  console.log("warning",data)
})
 
 
client.set("key2", "value", redis.print);
client.get("key2", redis.print);

执行分析

NODE_DEBUG=redis node test.js

日志信息

 

 


通过分析日志信息,搜索相关代码:

 
RedisClient.prototype.on_info_cmd = function (err, res) {
    if (err) {
        if (err.message === "ERR unknown command 'info'") {
            this.on_ready();
            return;
        }
        err.message = 'Ready check failed: ' + err.message;
        this.emit('error', err);
        return;
    }
 
    /* istanbul ignore if: some servers might not respond with any info data. This is just a safety check that is difficult to test */
    if (!res) {
        debug('The info command returned without any data.');
        this.on_ready();
        return;
    }
 
    if (!this.server_info.loading || this.server_info.loading === '0' ) {
        // If the master_link_status exists but the link is not up, try again after 50 ms
        if (this.server_info.master_link_status && this.server_info.master_link_status !== 'up') {
            this.server_info.loading_eta_seconds = 0.05;
        } else {
            // Eta loading should change
            debug('Redis server ready.');
            this.on_ready();
            return;
        }
    }
 
    var retry_time = +this.server_info.loading_eta_seconds * 1000;
    if (retry_time > 1000) {
        retry_time = 1000;
    }
    // 日志问题
    debug('Redis server still loading, trying again in ' + retry_time);
    setTimeout(function (self) {
        self.ready_check();
    }, retry_time, this);
};
  • 解决
    看到错误信息,目前就可以基本确定是info 的问题了,通过登陆redis以及tendis输出info,发现差异的地方

     

     

  • 参考解决方法
    对于node-redis 的info 处理添加-1 的处理
 
 if (!this.server_info.loading || this.server_info.loading === '0' || this.server_info.loading === '-1' ) {
        // If the master_link_status exists but the link is not up, try again after 50 ms
        if (this.server_info.master_link_status && this.server_info.master_link_status !== 'up') {
            this.server_info.loading_eta_seconds = 0.05;
        } else {
            // Eta loading should change
            debug('Redis server ready.');
            this.on_ready();
            return;
        }
    }
 
 

说明

经过测试发现还是有一些问题的,兼容性并不是特别好(尤其在集成cube.js 的时候发现了其他问题,比如multi 的问题),所以如果redis对于业务影响是比较大的话
还是慎重进行切换,做好完备的测试,以下是事务命令的兼容说明,可以参考

参考资料

https://github.com/go-redis/redis
http://tendis.cn/#/Tendisplus/%E6%95%B4%E4%BD%93%E4%BB%8B%E7%BB%8D/redis%E5%85%BC%E5%AE%B9%E6%80%A7

posted on   荣锋亮  阅读(200)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-04-26 fusionauth 通用sso 解决方案学习二 基本试用
2020-04-26 zeeqs 一个通用的zeebe 数据查询服务
2020-04-26 zeebe 0.23.1 变动说明
2020-04-26 fusionauth 通用sso 解决方案学习一 环境运行
2020-04-26 zeebe 0.23.1 发布
2019-04-26 Flagr 配置说明
2019-04-26 Flagr 架构

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示