Skip to content

Commit

Permalink
docs: sync bull document
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Feb 27, 2024
1 parent b661d1b commit 6168fb2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
17 changes: 14 additions & 3 deletions site/docs/extensions/bull.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,12 @@ export default {

原因是 redis 会对 key 做 hash 来确定存储的 slot,集群下这一步 @midwayjs/bull 的 key 命中了不同的 slot。

解决办法是 task 里的 prefix 配置用 {} 包括,强制 redis 只计算 {} 里的hash,例如 `prefix: '{midway-task}'`
解决方案: task 里的 prefix 配置用 {} 包括,强制 redis 只计算 {} 里的hash,例如 `prefix: '{midway-task}'`

### 2、EVAL inside MULTI is not allowed 错误

表现为 `queue.createBulk()``job.moveToFailed()` 等任务队列 API 调用无效,并出现下面的错误。

```
ReplyError: EXECABORT Transaction discarded because of previous errors.
at parseError (<project_dir>/node_modules/redis-parser/lib/parser.js:179:12)
Expand All @@ -831,6 +833,15 @@ ReplyError: EXECABORT Transaction discarded because of previous errors.
}
```

问题表现为 queue.createBulk()、job.moveToFailed() 等任务队列 API 调用无效,这些 API 依赖的 Redis Lua 脚本中使用了 EVAL 或者 EVALSHA。报错的原因是阿里云 Redis 使用代理模式连接时,会对 Lua 脚本调用做额外限制,包括不允许在 MULTI 事务中执行 EVAL 命令(<https://help.aliyun.com/zh/redis/support/usage-of-lua-scripts?#section-8f7-qgv-dlv>),文档中还提到可以通过参数配置 script_check_enable 关闭这一校验,但是验证无效。
::: tip

常出现与使用阿里云 Redis 服务时。

:::

由于这些 API 依赖的 Redis Lua 脚本中使用了 EVAL 或者 EVALSHA,阿里云 Redis 使用代理模式连接时,会对 Lua 脚本调用做额外限制,包括 [不允许在 MULTI 事务中执行 EVAL 命令](https://help.aliyun.com/zh/redis/support/usage-of-lua-scripts?#section-8f7-qgv-dlv),文档中还提到可以通过参数配置 script_check_enable 关闭这一校验,但是验证无效。

解决方案:

好在切换到直连模式可以解决这个问题,可以在阿里云控制台操作开启直连地址,由于直连模式需要客户端切换成集群模式,需要参考前文中的「Redis 集群」章节,切换成 defaultQueueOptions.createClient 配置方式。
* 1、在阿里云控制台操作开启直连地址,将服务切换到直连模式
* 2、客户端切换成集群模式,参考上述「Redis 集群」章节,切换配置方式
Original file line number Diff line number Diff line change
Expand Up @@ -809,5 +809,36 @@ This problem is basically clear, the problem will appear on the clustered versio

The reason is that redis does hash on the key to determine the storage slot, and the key of @midwayjs/bull hits a different slot in this step under the cluster.

The workaround is to include {} in the prefix configuration of the task and force redis to only calculate the hash in {}, e.g. `prefix: '{midway-task}'`.
Solution: The prefix configuration in the task is included with {} to force redis to only calculate the hash in {}, for example `prefix: '{midway-task}'`.

### 2. EVAL inside MULTI is not allowed error

This shows that task queue API calls such as `queue.createBulk()` and `job.moveToFailed()` are invalid and the following error occurs.

```
ReplyError: EXECABORT Transaction discarded because of previous errors.
at parseError (<project_dir>/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (<project_dir>/node_modules/redis-parser/lib/parser.js:302:14) {
command: { name: 'exec', args: [] },
previousErrors: [
ReplyError: ERR 'EVAL' inside MULTI is not allowed
at parseError (<project_dir>/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (<project_dir>/node_modules/redis-parser/lib/parser.js:302:14) {
command: [Object]
}
]
}
```

::: tip

Often occurs when using Alibaba Cloud Redis service.

:::

Since EVAL or EVALSHA are used in the Redis Lua scripts that these APIs depend on, when Alibaba Cloud Redis uses proxy mode to connect, additional restrictions will be placed on Lua script calls, including [EVAL commands are not allowed to be executed in MULTI transactions] (https:// help.aliyun.com/zh/redis/support/usage-of-lua-scripts?#section-8f7-qgv-dlv), the document also mentions that this verification can be turned off through parameter configuration script_check_enable, but the verification is invalid.

Solution:

* 1. Open the direct connection address in the Alibaba Cloud console and switch the service to direct connection mode.
* 2. Switch the client to cluster mode. Refer to the above "Redis Cluster" chapter to switch the configuration mode.

0 comments on commit 6168fb2

Please sign in to comment.