Kubernetes上的Redis主/从设置会引发错误:BRPOPLPUSH {ReplyError:MOVED 2651

bob*_*obb 5 redis kubernetes bull.js

我正在使用基于Redis的优秀Bull.js作为Kubernetes上的工作队列。

它配置为集群:

在此处输入图片说明

当Kubernetes在部署时重新启动时,我遇到以下错误:

BRPOPLPUSH { ReplyError: MOVED 2651 <IP_ADDRESS>:6379
at parseError (/usr/src/app/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/usr/src/app/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:302:14)
command:
{ name: 'brpoplpush',
args:
[ '{slack}:slack notifications:wait',
'{slack}:slack notifications:active',
'5' ] } }
Run Code Online (Sandbox Code Playgroud)

<IP_ADDRESS>认为群集IP 在哪里?我没有配置它,但是我正在尝试调试它。我想知道是否需要为Bull.js启用集群模式,或者这是Bull.js项目之外的配置问题?

还是K8的网络问题?

是否将启用:https : //github.com/OptimalBits/bull#cluster-support是解决方案?这是正确的方法吗?

这是我的代码:

import Queue from 'bull';
import config from 'config';
import { run as slackRun } from './tasks/send-slack-message';
import { run as emailRun } from './tasks/send-email';

const redisConfig = {
  redis: {
    host: config.redis.host,
    port: config.redis.port
  }
};

const slackQueue = new Queue('slack notifications', { ...redisConfig, ...{ prefix: '{slack}' } });
const emailQueue = new Queue('email notifications', { ...redisConfig, ...{ prefix: '{email}' } });

slackQueue.process(slackRun);
emailQueue.process(emailRun);

emailQueue.on('completed', (job, result) => {
  job.remove();
});

export { emailQueue, slackQueue };
Run Code Online (Sandbox Code Playgroud)
import { emailQueue, slackQueue } from 'worker/worker';

const queueOptions = {
  attempts: 2,
  removeOnComplete: true,
  backoff: {
    type: 'exponential',
    delay: 60 * 1000
  }
};

emailQueue.add(
  {
    params: {
      from: email,
      fromname: name,
      text: body
    }
  },
  queueOptions
);
slackQueue.add(
  {
    channelId: SLACK_CHANNELS.FEEDBACK,
    attachments: [
      {
        text: req.body.body
      }
    ]
  },
  queueOptions
);
Run Code Online (Sandbox Code Playgroud)

这是配置图:

Name:         redis-cluster-config
Namespace:    default
Labels:       <none>
Annotations:  <none>

Data
====
update-node.sh:
----
#!/bin/sh
REDIS_NODES="/data/nodes.conf"
sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${REDIS_NODES}
exec "$@"

redis.conf:
----
cluster-enabled yes
cluster-require-full-coverage no
cluster-node-timeout 15000
cluster-config-file nodes.conf
cluster-migration-barrier 1
appendonly yes
# Other cluster members need to be able to connect
protected-mode no

Events:  <none>
Run Code Online (Sandbox Code Playgroud)

Ser*_*hny 4

Hitobat是对的。

如果这没有帮助:

const Redis = require('ioredis');
...
const ioCluster = new Redis.Cluster([redisConfig.redis]);
const slackQueue = new Queue('slack notifications', {
  prefix: '{slack}' ,
  createClient: () => ioCluster
});
const emailQueue = new Queue('email notifications', {
  prefix: '{email}' ,
  createClient: () => ioCluster
});
Run Code Online (Sandbox Code Playgroud)

我会不使用 ioredis 或尝试将 redis 引擎降级到 4.x。