-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOORedis.js
33 lines (29 loc) · 820 Bytes
/
OORedis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use strict"
var Observable = require('rxjs').Observable
var redis = require('redis')
var module = module || {}
module.exports = function OORedis (redisCmdName, redisParams, redisConfig) {
return Observable.create(function (observer) {
var rclient = redis.createClient(redisConfig.port, redisConfig.host)
rclient.on('connect', function () {
asserts()
rclient[redisCmdName](redisParams, (err, result) => {
if ( null !== err) {
observer.error(err)
}
observer.next(result)
observer.complete()
})
})
function asserts () {
if ( !typeof rclient[redisCmdName] === 'function' ) {
observer.error( redisCmdName + ' not valid redis cmd')
}
}
return {
unsubscribe: function () {
rclient.quit()
},
}
})
}