eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.84k stars 1.81k forks source link

egg-redis 集群连接问题以及配置优化建议 #2983

Closed seekcx closed 5 years ago

seekcx commented 5 years ago

https://github.com/eggjs/egg-redis/blob/master/lib/redis.js#L19-L20 第一个问题,这个验证过于绝对,集群链接时,密码是通过 redisOptions 配置的。现在不配置密码参数插件直接报错了。

exports.redis = {
   client: {
     cluster: true,
     nodes: [{
       host: '127.0.0.1',
       port: '6379',
     }],
     redisOptions: {
        password: 'secret',
     }
   },
};

https://github.com/eggjs/egg-redis/blob/master/lib/redis.js#L24 第二个问题,这里直接使用整个 client 的配置作为第二个参数传递给了 Redis.Cluster,抛出了

Failed to refresh slots cache. 错误

[ioredis] Unhandled error event: Error: Failed to refresh slots cache.
    at tryNode (/Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/cluster/index.js:375:19)
    at /Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/cluster/index.js:387:9
    at /Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/cluster/index.js:591:14
    at run (/Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/utils/index.js:153:16)
    at tryCatcher (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/util.js:16:23)
    at Promise.errorAdapter [as _rejectionHandler0] (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/nodeify.js:35:34)
    at Promise._settlePromise (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/promise.js:566:21)
    at Promise._settlePromise0 (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/promise.js:690:18)
    at _drainQueueStep (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:138:12)
    at _drainQueue (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:810:20)
    at tryOnImmediate (timers.js:768:5)
    at processImmediate [as _immediateCallback] (timers.js:745:5)

修改源码固定传递

redisOptions: {
    password: 'secret',
}

之后没有此问题。

猜测是否是参数名发生了冲突? 建议增加一个单独的参数来配置。

egg-bot commented 5 years ago

Translation of this issue:


egg-redis Cluster connection issues and configuration optimization tips

https://github.com/eggjs/egg-redis/blob/master/lib/redis.js#L19-L20 The first problem, this verification is too absolute, when the cluster is linked, the password is configured via redisOptions. Now I don't configure the password parameter plugin to report an error directly.

Exports.redis = {
   Client: {
     Cluster: true,
     Nodes: [{
       Host: '127.0.0.1',
       Port: '6379',
     }],
     redisOptions: {
        Password: 'secret',
     }
   },
};

https://github.com/eggjs/egg-redis/blob/master/lib/redis.js#L24 The second problem, here directly using the entire client configuration as the second parameter passed to Redis.Cluster, thrown

Failed to refresh slots cache. Error

[ioredis] Unhandled error event: Error: Failed to refresh slots cache.
    At tryNode (/Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/cluster/index.js:375:19)
    At /Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/cluster/index.js:387:9
    At /Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/cluster/index.js:591:14
    At run (/Users/abel/Desktop/work/smart-investment/node_modules/ioredis/lib/utils/index.js:153:16)
    At tryCatcher (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/util.js:16:23)
    At Promise.errorAdapter [as _rejectionHandler0] (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/nodeify.js:35:34)
    At Promise._settlePromise (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/promise.js:566:21)
    At Promise._settlePromise0 (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/promise.js:614:10)
    At Promise._settlePromises (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/promise.js:690:18)
    At _drainQueueStep (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:138:12)
    At _drainQueue (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:131:9)
    At Async._drainQueues (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:147:5)
    At Immediate.Async.drainQueues (/Users/abel/Desktop/work/smart-investment/node_modules/bluebird/js/release/async.js:17:14)
    At runCallback (timers.js:810:20)
    At tryOnImmediate (timers.js:768:5)
    At processImmediate [as _immediateCallback] (timers.js:745:5)

Modify source fixed transmission

redisOptions: {
    Password: 'secret',
}

There is no such problem after that.

Guess if there is a conflict with the parameter name? It is recommended to add a separate parameter to configure.

seekcx commented 5 years ago

密码写错了。。打扰了。