diff --git a/dist/index.js b/dist/index.js index 9fea7dc..01752b8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -18,7 +18,11 @@ const redisStore = (...args) => { redisCache = new Redis(...args); } - const storeArgs = redisCache.options; + const storeArgs = { + ...redisCache.options, + ttl: args.length > 0 ? args[0].ttl : undefined + }; + let self = { name: 'redis', diff --git a/index.js b/index.js index 09ee778..5e109b3 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,11 @@ const redisStore = (...args) => { redisCache = new Redis(...args); } - const storeArgs = redisCache.options; + const storeArgs = { + ...redisCache.options, + ttl: args.length > 0 ? args[0].ttl : undefined + }; + let self = { name: 'redis', diff --git a/test/index.test.js b/test/index.test.js index 253cedb..8ea650e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -132,6 +132,28 @@ describe('set', () => { }); }); + it('should respect the ttl option when supplied an external redis instance', (done) => { + const externalRedisInstanceCache = cacheManager.caching({ + store: redisStore, + redisInstance: new Redis({ + host: config.host, + port: config.port, + password: config.password, + db: config.db, + }), + ttl: 123 + }); + + externalRedisInstanceCache.set('foo', 'bar', (err) => { + expect(err).toEqual(null); + redisCache.ttl('foo', (err, ttl) => { + expect(err).toEqual(null); + expect(ttl).toEqual(123); + done(); + }); + }); + }); + it('should not be able to store a null value (not cacheable)', (done) => { redisCache.set('foo2', null, (err) => { if (err) {