-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathioRedisStore.js
More file actions
36 lines (29 loc) · 764 Bytes
/
Copy pathioRedisStore.js
File metadata and controls
36 lines (29 loc) · 764 Bytes
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
'use strict'
const debug = require('debug')('route-cache')
// This store is designed to work with https://github.com/luin/ioredis
class IoRedisStore {
constructor (redisClient) {
this.client = redisClient
}
async get (key) {
debug('get: ' + key)
return this.client.get(key).then((val) => {
if (val === null) return val
return JSON.parse(val)
})
}
// Value must be a json-serializable object.
async set (key, value, ttlMillis) {
debug('set: ' + key)
return this.client.set(key, JSON.stringify(value), 'PX', ttlMillis)
}
async del (key) {
debug('del: ' + key)
return this.client.del(key)
}
async clear () {
debug('clear')
return this.client.flushdb()
}
}
module.exports = IoRedisStore