@@ -60,12 +60,28 @@ function Redis (opts) {
60
60
}
61
61
}
62
62
63
- var redis = opts . redis || require ( 'redis' ) ;
63
+ var redis = opts . redis || require ( 'redis' )
64
+ , RedisClient = redis . RedisClient ;
64
65
65
66
// initialize a pubsub client and a regular client
66
- this . pub = redis . createClient ( opts . redisPub ) ;
67
- this . sub = redis . createClient ( opts . redisSub ) ;
68
- this . cmd = redis . createClient ( opts . redisClient ) ;
67
+ if ( opts . redisPub instanceof RedisClient ) {
68
+ this . pub = opts . redisPub ;
69
+ } else {
70
+ opts . redisPub || ( opts . redisPub = { } ) ;
71
+ this . pub = redis . createClient ( opts . redisPub . port , opts . redisPub . host , opts . redisPub ) ;
72
+ }
73
+ if ( opts . redisSub instanceof RedisClient ) {
74
+ this . sub = opts . redisSub ;
75
+ } else {
76
+ opts . redisSub || ( opts . redisSub = { } ) ;
77
+ this . sub = redis . createClient ( opts . redisSub . port , opts . redisSub . host , opts . redisSub ) ;
78
+ }
79
+ if ( opts . redisClient instanceof RedisClient ) {
80
+ this . cmd = opts . redisClient ;
81
+ } else {
82
+ opts . redisClient || ( opts . redisClient = { } ) ;
83
+ this . cmd = redis . createClient ( opts . redisClient . port , opts . redisClient . host , opts . redisClient ) ;
84
+ }
69
85
70
86
Store . call ( this , opts ) ;
71
87
} ;
@@ -118,7 +134,7 @@ Redis.prototype.subscribe = function (name, consumer, fn) {
118
134
self . on ( 'unsubscribe' , function unsubscribe ( ch ) {
119
135
if ( name == ch ) {
120
136
self . sub . removeListener ( 'message' , message ) ;
121
- self . removeEvent ( 'unsubscribe' , unsubscribe ) ;
137
+ self . removeListener ( 'unsubscribe' , unsubscribe ) ;
122
138
}
123
139
} ) ;
124
140
0 commit comments