eggjs / eggjs/egg

egg-redis 配置 redisOptions 时的缺陷

Open
#4,291 4 comments 0 reactions 0 assignees View on GitHub
Inactive
Dominant language
TypeScript
Stars
19k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

## 问题描述
当使用集群模式时,`ioredis` 本身可以只配置部分机器。通过 `redisOptions` 配置默认 `option`。
如: redis 集群有 4 台机器 `172.20.10.21 ~ 24`。
`ioredis` 配置:
``` javascript
const Redis = require("ioredis");

const nodes = [ 21, 22 ].map(ip => ({
port: 6379,
host: `172.20.10.${ip}`
}))
const options = {
redisOptions: {
password: "xxxx",
db: 0,
}
}
const cluster = new Redis.Cluster(nodes, options)

```
而`egg-redis` 强制要求每台机器必须配置自己的密码,会导致下面冗余的配置:
```javascript
config.redis = {
client: {
cluster: true,
redisOptions: {
password: 'xxxx',
db: 0,
},
nodes: [ 21, 22 ].map(ip => ({
port: 6379,
host: `172.20.10.${ip}`,
password: 'xxxx',
db: 0,
}))
}
}
```
如果每个节点都配置的不便包括:
* 每次加机器都需要更新 ip 配置
* 如果存在只读的备份节点也需要配置进来

## 相关环境信息
- **操作系统**:
osx 10.15
- **Node 版本**:
v8.11.4
- **Egg 版本**:
"egg": "^2.15.1",
"egg-redis": "^2.4.0",

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.