forked from mike-zorn/romis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 867 Bytes
/
index.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
34
35
36
37
var redis = require('redis'),
_ = require('lodash'),
Promise = require('bluebird');
exports.fromRedis = function(client)
{
var allFunctions = _.functions(client);
var result= Object.create(client);
result._redis = client;
_.each(allFunctions, function(command) {
if(command.search(/^[A-Z]+$/)===-1) return;
result[command] = result[command.toLowerCase()] = function() {
var args = _.toArray(arguments);
return new Promise(function(resolve, reject) {
client[command].apply(client, args.concat([function(err, data) {
if(err) {
reject(err);
}
else {
resolve(data);
}
}]));
});
};
});
return result;
}
exports.createClient = function()
{
var client = redis.createClient.apply(redis, arguments);
return exports.fromRedis(client);
}