-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 887 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
38
39
var Q = require('q');
var Memcached = require('memcached');
const ASYNC_METHODS = [
'touch',
'get',
'gets',
'getMulti',
'set',
'replace',
'add',
'cas',
'append',
'preprend',
'incr',
'decr',
'del'
];
var MemcachedQ = function (serverLocations, options) {
this._memcached = new Memcached(serverLocations, options);
// Auto-generate delegation to _memcached for all methods
// on its API, using Q.nbind for things that ought to
// return promises.
for (var p in this._memcached) {
if (typeof this._memcached[p] === 'function') {
if (ASYNC_METHODS.indexOf(p) === -1) {
this[p] = this._memcached[p].bind(this._memcached);
} else {
this[p] = Q.nbind(this._memcached[p], this._memcached);
}
}
}
};
module.exports = MemcachedQ;