File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,10 @@ const redisStore = (...args) => {
1818 redisCache = new Redis ( ...args ) ;
1919 }
2020
21- const storeArgs = redisCache . options ;
21+ const storeArgs = {
22+ ttl : args . length > 0 && args [ 0 ] . ttl ,
23+ ...redisCache . options
24+ } ;
2225
2326 let self = {
2427 name : 'redis' ,
Original file line number Diff line number Diff line change @@ -16,7 +16,10 @@ const redisStore = (...args) => {
1616 redisCache = new Redis ( ...args ) ;
1717 }
1818
19- const storeArgs = redisCache . options ;
19+ const storeArgs = {
20+ ttl : args . length > 0 && args [ 0 ] . ttl ,
21+ ...redisCache . options
22+ } ;
2023
2124 let self = {
2225 name : 'redis' ,
Original file line number Diff line number Diff line change @@ -132,6 +132,28 @@ describe('set', () => {
132132 } ) ;
133133 } ) ;
134134
135+ it ( 'should respect the ttl option when supplied an external redis instance' , ( done ) => {
136+ const externalRedisInstanceCache = cacheManager . caching ( {
137+ store : redisStore ,
138+ redisInstance : new Redis ( {
139+ host : config . host ,
140+ port : config . port ,
141+ password : config . password ,
142+ db : config . db ,
143+ } ) ,
144+ ttl : 123
145+ } ) ;
146+
147+ externalRedisInstanceCache . set ( 'foo' , 'bar' , ( err ) => {
148+ expect ( err ) . toEqual ( null ) ;
149+ redisCache . ttl ( 'foo' , ( err , ttl ) => {
150+ expect ( err ) . toEqual ( null ) ;
151+ expect ( ttl ) . toEqual ( 123 ) ;
152+ done ( ) ;
153+ } ) ;
154+ } ) ;
155+ } ) ;
156+
135157 it ( 'should not be able to store a null value (not cacheable)' , ( done ) => {
136158 redisCache . set ( 'foo2' , null , ( err ) => {
137159 if ( err ) {
You can’t perform that action at this time.
0 commit comments