|
|
@ -6,15 +6,15 @@ const pify = require('pify'); |
|
|
|
class KeyvRedis { |
|
|
|
constructor(opts) { |
|
|
|
this.ttlSupport = true; |
|
|
|
const client = redis.createClient(opts); |
|
|
|
this.client = ['get', 'set', 'del', 'flushdb'].reduce((obj, method) => { |
|
|
|
obj[method] = pify(client[method].bind(client)); |
|
|
|
this.client = redis.createClient(opts); |
|
|
|
this.redis = ['get', 'set', 'del', 'flushdb'].reduce((obj, method) => { |
|
|
|
obj[method] = pify(this.client[method].bind(this.client)); |
|
|
|
return obj; |
|
|
|
}, {}); |
|
|
|
} |
|
|
|
|
|
|
|
get(key) { |
|
|
|
return this.client.get(key) |
|
|
|
return this.redis.get(key) |
|
|
|
.then(value => { |
|
|
|
if (value === null) { |
|
|
|
return undefined; |
|
|
@ -28,19 +28,19 @@ class KeyvRedis { |
|
|
|
.then(() => { |
|
|
|
value = JSON.stringify(value); |
|
|
|
if (typeof ttl === 'number') { |
|
|
|
return this.client.set(key, value, 'PX', ttl); |
|
|
|
return this.redis.set(key, value, 'PX', ttl); |
|
|
|
} |
|
|
|
return this.client.set(key, value); |
|
|
|
return this.redis.set(key, value); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
delete(key) { |
|
|
|
return this.client.del(key) |
|
|
|
return this.redis.del(key) |
|
|
|
.then(items => items > 0); |
|
|
|
} |
|
|
|
|
|
|
|
clear() { |
|
|
|
return this.client.flushdb() |
|
|
|
return this.redis.flushdb() |
|
|
|
.then(() => undefined); |
|
|
|
} |
|
|
|
} |
|
|
|