You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地环境可见Redis Keys但Redis集群中无法查看的问题

Redis集群中无法查看程序生成的键的问题

我开发了一个利用Redis键实现消息排序的程序:在本地单实例Redis中运行时,键能正常生成且程序功能完全正常,但部署到Redis集群后,无法在集群中查看到这些键。

集群连接代码

constructor() {
        const clusterEndpoints = [{ host: env.REDIS_ENDPOINT, port: parseInt(env.REDIS_PORT) }];
        const redisPassword = env.REDIS_PASSWORD;

        const sslOptions = {
            tls: {
                rejectUnauthorized: false,
                minVersion: 'TLSv1.2' as const,
            },
        };

        const clusterOptions: ClusterOptions = {
            redisOptions: {
                password: redisPassword,
                ...sslOptions,
            },
        };

        this.client = new Redis.Cluster(clusterEndpoints, clusterOptions);

        // Log connection success
        this.client.on('connect', () => {
            logger.info('Successfully connected to Redis cluster at:', clusterEndpoints);
        });
    }

消息排序函数(调用Lua脚本)

public async sortMessage(message: Message, messageTimestamp: number): Promise<number | null> {
        try {
            const heapKey = `{message_heap}`;
            const lastTsKey = `{message_heap}:last_ts`;
            const brandLastTsKey = `{message_heap}:brand_last_ts`;
            const brandCntKey = `{message_heap}:brand_count`;

            await this.client.eval(
                this.insertScript,
                4, // Number of keys
                lastTsKey,
                brandLastTsKey,
                brandCntKey,
                heapKey,
                String(messageTimestamp),
                String(limit),
                JSON.stringify(message),
            );

            return messageTimestamp;
        } catch (error) {
            logger.error('Error sorting message:', error);
            return null;
        }
    }

已做排查

  • Lua脚本在本地环境运行正常,排除脚本本身问题
  • 确认集群连接正常,程序拥有读写及执行命令的权限
  • 所有键都通过{message_heap}前缀确保落在同一哈希槽中
  • 使用带-c参数的redis-cli连接集群,执行GET <key_name>查询字符串键,但始终无法找到对应键
  • 集群包含主节点和从节点,不存在访问错误节点的问题

期望通过redis-cli能在集群中看到这些键及其对应的值,但目前无法实现。

redis-cli连接命令

redis-cli -h <host> -p 6379 -a <password> --tls --no-auth-warning --insecure -c

内容的提问来源于stack exchange,提问作者trufflewaffle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 16:11:18