Expire values in RedisCacheAdapter (#2988)
This commit is contained in:
committed by
Florent Vilmart
parent
f3c656829a
commit
33ebedfd6a
@@ -1,6 +1,8 @@
|
|||||||
import redis from 'redis';
|
import redis from 'redis';
|
||||||
import logger from '../../logger';
|
import logger from '../../logger';
|
||||||
|
|
||||||
|
const DEFAULT_REDIS_TTL = 30 * 1000; // 30 seconds
|
||||||
|
|
||||||
function debug() {
|
function debug() {
|
||||||
logger.debug.apply(logger, ['RedisCacheAdapter', ...arguments]);
|
logger.debug.apply(logger, ['RedisCacheAdapter', ...arguments]);
|
||||||
}
|
}
|
||||||
@@ -33,9 +35,15 @@ export class RedisCacheAdapter {
|
|||||||
debug('put', key, value, ttl);
|
debug('put', key, value, ttl);
|
||||||
this.p = this.p.then(() => {
|
this.p = this.p.then(() => {
|
||||||
return new Promise((resolve, _) => {
|
return new Promise((resolve, _) => {
|
||||||
this.client.set(key, value, function(err, res) {
|
if (ttl) {
|
||||||
resolve();
|
this.client.psetex(key, ttl, value, function(err, res) {
|
||||||
});
|
resolve();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.client.set(key, value, function(err, res) {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return this.p;
|
return this.p;
|
||||||
|
|||||||
Reference in New Issue
Block a user