首页 > 解决方案 > Redis 集群连接丢失

问题描述

我有一个使用 bitnami/redis-cluster 图表部署在 Kubernetes 中的 Redis 集群。我使用 redis-cluster npm 包从 nodejs 连接到集群。建立连接后,我尝试连续设置数千个键。完成所有过程的时间预计为十分钟。但连接两分钟后,Redis 连接丢失。

是否是连接问题,我该怎么办?比如改变配置什么的。

在我的场景或常见场景中丢失连接的确切原因可能是什么?

我的代码:

const redis = require('redis');
const redisCluster = require('redis-clustr')
const redisClient = new redisCluster({
    servers: [
    { host: "IP", port: 6379 },
    { host: "IP", port: 6379 }, 
    { host: "IP", port: 6379 },  
    { host: "IP", port: 6379 },
    { host: "IP", port: 6379 }, 
    { host: "IP", port: 6379 } 
     ],
    createClient: (port, host) => {
      return redis.createClient({ 
       port,
       host,
       auth_pass: 'PASSWORD',
     });
   }
});
 <My data processing code to set thousands of keys>
(node:15827) UnhandledPromiseRejectionWarning: AbortError: Redis connection lost and command aborted. It might have been processed.
    at RedisClient.flush_and_error (/root/data-pipeline/node_modules/redis/index.js:362:23)
    at RedisClient.connection_gone (/root/data-pipeline/node_modules/redis/index.js:664:14)
    at Socket.<anonymous> (/root/data-pipeline/node_modules/redis/index.js:293:14)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:15827) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15827) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

标签: kubernetesredisbitnaminode-redisredis-cluster

解决方案


推荐阅读