Skip to content

Commit 32c48ef

Browse files
r3b-fishluin
authored andcommitted
fix: subscriber initialization when using Cluster (#792)
Close: #791
1 parent f46490d commit 32c48ef

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

lib/cluster/ClusterSubscriber.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default class ClusterSubscriber {
7171
password: options.password,
7272
enableReadyCheck: true,
7373
connectionName: SUBSCRIBER_CONNECTION_NAME,
74-
lazyConnect: true
74+
lazyConnect: true,
75+
tls: options.tls
7576
})
7677

7778
// Ignore the errors since they're handled in the connection pool.

test/functional/cluster/tls.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict'
2+
3+
import * as tls from 'tls'
4+
import * as net from 'net'
5+
6+
describe('cluster:tls option', () => {
7+
it('supports tls', (done) => {
8+
var slotTable = [
9+
[0, 5460, ['127.0.0.1', 30001]],
10+
[5461, 10922, ['127.0.0.1', 30002]],
11+
[10923, 16383, ['127.0.0.1', 30003]]
12+
];
13+
var argvHandler = function (argv) {
14+
if (argv[0] === 'cluster' && argv[1] === 'slots') {
15+
return slotTable;
16+
}
17+
};
18+
19+
new MockServer(30001, argvHandler)
20+
new MockServer(30002, argvHandler)
21+
new MockServer(30003, argvHandler)
22+
23+
stub(tls, 'connect', (op) => {
24+
expect(op.ca).to.eql('123')
25+
expect(op.port).to.be.oneOf([30001, 30003, 30003])
26+
const stream = net.createConnection(op)
27+
stream.on('connect', data => {
28+
stream.emit('secureConnect', data)
29+
})
30+
return stream
31+
})
32+
33+
var cluster = new Redis.Cluster([
34+
{ host: '127.0.0.1', port: '30001' },
35+
{ host: '127.0.0.1', port: '30002' },
36+
{ host: '127.0.0.1', port: '30003' }
37+
], {
38+
redisOptions: { tls: { ca: '123' } }
39+
})
40+
41+
cluster.on('ready', () => {
42+
expect(cluster.subscriber.subscriber.options.tls)
43+
.to.deep.equal({ ca: '123' })
44+
45+
cluster.disconnect()
46+
tls.connect.restore()
47+
cluster.on('end', () => done())
48+
})
49+
})
50+
})

0 commit comments

Comments
 (0)