Skip to content

Commit 2d750ac

Browse files
committed
Expire values in RedisCacheAdapter
1 parent 583887c commit 2d750ac

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Adapters/Cache/RedisCacheAdapter.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import redis from 'redis';
22
import logger from '../../logger';
33

4+
const DEFAULT_REDIS_TTL = 30 * 1000; // 30 seconds
5+
46
function debug() {
57
logger.debug.apply(logger, ['RedisCacheAdapter', ...arguments]);
68
}
@@ -29,11 +31,14 @@ export class RedisCacheAdapter {
2931
}
3032

3133
put(key, value, ttl) {
34+
if (!ttl || isNaN(ttl)) {
35+
ttl = DEFAULT_CACHE_TTL;
36+
}
3237
value = JSON.stringify(value);
3338
debug('put', key, value, ttl);
3439
this.p = this.p.then(() => {
3540
return new Promise((resolve, _) => {
36-
this.client.set(key, value, function(err, res) {
41+
this.client.psetex(key, ttl, value, function(err, res) {
3742
resolve();
3843
});
3944
});

0 commit comments

Comments
 (0)