File tree 3 files changed +32
-5
lines changed
3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -52,16 +52,17 @@ export default class ClusterSubscriber {
52
52
return
53
53
}
54
54
55
- const { port , host } = sampleNode . options
56
- debug ( 'selected a subscriber %s:%s' , host , port )
55
+ const { options } = sampleNode
56
+ debug ( 'selected a subscriber %s:%s' , options . host , options . port )
57
57
58
58
// Create a specialized Redis connection for the subscription.
59
59
// Note that auto reconnection is enabled here.
60
60
// `enableReadyCheck` is disabled because subscription is allowed
61
61
// when redis is loading data from the disk.
62
62
this . subscriber = new Redis ( {
63
- port,
64
- host,
63
+ port : options . port ,
64
+ host : options . host ,
65
+ password : options . password ,
65
66
enableReadyCheck : false ,
66
67
connectionName : SUBSCRIBER_CONNECTION_NAME ,
67
68
lazyConnect : true
Original file line number Diff line number Diff line change @@ -45,6 +45,31 @@ describe('cluster:pub/sub', function () {
45
45
} ) ;
46
46
} ) ;
47
47
48
+ it ( 'supports password' , function ( done ) {
49
+ const handler = function ( argv , c ) {
50
+ if ( argv [ 0 ] === 'auth' ) {
51
+ c . password = argv [ 1 ]
52
+ return
53
+ }
54
+ if ( argv [ 0 ] === 'subscribe' ) {
55
+ expect ( c . password ) . to . eql ( 'abc' )
56
+ expect ( c . getConnectionName ( ) ) . to . eql ( 'ioredisClusterSubscriber' )
57
+ }
58
+ if ( argv [ 0 ] === 'cluster' && argv [ 1 ] === 'slots' ) {
59
+ return [
60
+ [ 0 , 16383 , [ '127.0.0.1' , 30001 ] ]
61
+ ] ;
62
+ }
63
+ } ;
64
+ new MockServer ( 30001 , handler ) ;
65
+
66
+ var sub = new Redis . Cluster ( [ { port : '30001' , password : 'abc' } ] ) ;
67
+
68
+ sub . subscribe ( 'test cluster' , function ( ) {
69
+ done ( ) ;
70
+ } ) ;
71
+ } ) ;
72
+
48
73
it ( 'should re-subscribe after reconnection' , function ( done ) {
49
74
new MockServer ( 30001 , function ( argv ) {
50
75
if ( argv [ 0 ] === 'cluster' && argv [ 1 ] === 'slots' ) {
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ util.inherits(MockServer, EventEmitter);
47
47
MockServer . prototype . connect = function ( ) {
48
48
var _this = this ;
49
49
this . socket = net . createServer ( function ( c ) {
50
+ c . getConnectionName = ( ) => ( c . _connectionName )
50
51
var clientIndex = _this . clients . push ( c ) - 1 ;
51
52
process . nextTick ( function ( ) {
52
53
_this . emit ( 'connect' , c ) ;
@@ -59,7 +60,7 @@ MockServer.prototype.connect = function () {
59
60
if ( reply . length === 3 && reply [ 0 ] . toLowerCase ( ) === 'client' && reply [ 1 ] . toLowerCase ( ) === 'setname' ) {
60
61
c . _connectionName = reply [ 2 ]
61
62
}
62
- _this . write ( c , _this . handler && _this . handler ( reply ) ) ;
63
+ _this . write ( c , _this . handler && _this . handler ( reply , c ) ) ;
63
64
} ,
64
65
returnError : function ( ) { }
65
66
} ) ;
You can’t perform that action at this time.
0 commit comments