Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 22 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down