Skip to content

Commit

Permalink
Fix issue with custom connection and redis cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Grondin committed Jul 6, 2019
1 parent 50116d3 commit 6374222
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,8 @@
if (this.clusterNodes != null) {
this.client = new Redis.Cluster(this.clusterNodes, this.clientOptions);
this.subscriber = new Redis.Cluster(this.clusterNodes, this.clientOptions);
} else if (this.client != null && this.client.duplicate == null) {
this.subscriber = new Redis.Cluster(this.client.startupNodes, this.client.options);
} else {
if (this.client == null) {
this.client = new Redis(this.clientOptions);
Expand Down
2 changes: 2 additions & 0 deletions lib/IORedisConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ IORedisConnection = function () {
if (this.clusterNodes != null) {
this.client = new Redis.Cluster(this.clusterNodes, this.clientOptions);
this.subscriber = new Redis.Cluster(this.clusterNodes, this.clientOptions);
} else if (this.client != null && this.client.duplicate == null) {
this.subscriber = new Redis.Cluster(this.client.startupNodes, this.client.options);
} else {
if (this.client == null) {
this.client = new Redis(this.clientOptions);
Expand Down
2 changes: 2 additions & 0 deletions src/IORedisConnection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class IORedisConnection
if @clusterNodes?
@client = new Redis.Cluster @clusterNodes, @clientOptions
@subscriber = new Redis.Cluster @clusterNodes, @clientOptions
else if @client? and !@client.duplicate?
@subscriber = new Redis.Cluster @client.startupNodes, @client.options
else
@client ?= new Redis @clientOptions
@subscriber = @client.duplicate()
Expand Down
17 changes: 17 additions & 0 deletions test/ioredis.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ if (process.env.DATASTORE === 'ioredis') {
assert(c.limiter._store.connection.client.nodes().length >= 0)
})

it('Should connect in Redis Cluster mode with premade client', function () {
var client = new Redis.Cluster('')
var connection = new Bottleneck.IORedisConnection({ client })
c = makeTest({
maxConcurrent: 2,
clientOptions: {},
clusterNodes: [{
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT
}]
})

c.mustEqual(c.limiter.datastore, 'ioredis')
assert(c.limiter._store.connection.client.nodes().length >= 0)
connection.disconnect(false)
})

it('Should accept existing connections', function () {
var connection = new Bottleneck.IORedisConnection()
connection.id = 'super-connection'
Expand Down

0 comments on commit 6374222

Please sign in to comment.