-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (54 loc) · 1.59 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var redis = require('redis');
var client = redis.createClient();
module.exports = function() {
return {
set: function(key, value, hash, cb) {
if (typeof hash === 'function') {
cb = hash;
hash = undefined;
}
if (hash !== undefined) {
client.hset(hash, key, value, function(err, reply) {
cb(err, reply);
});
} else {
client.set(key, value, function(err, reply) {
cb(err, reply);
});
}
},
get: function(key, hash, cb) {
if (typeof hash === 'function') {
cb = hash;
hash = undefined;
}
if (hash !== undefined) {
client.hget(hash, key, function(err, reply) {
cb(err, reply);
});
} else {
client.get(key, function(err, reply) {
cb(err, reply);
});
}
},
del: function(key, field, cb) {
if (typeof field === 'function') {
cb = field;
field = undefined;
}
if (field !== undefined) {
client.hdel(field, key, function(err, reply) {
cb(err, reply);
});
} else {
client.del(key, function(err, reply) {
cb(err, reply);
});
}
},
quit: function() {
client.quit();
}
};
};