Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ttl option is ignored when constructed with an external redis instance #14

Open
wbk opened this issue Feb 3, 2021 · 3 comments · May be fixed by #21
Open

ttl option is ignored when constructed with an external redis instance #14

wbk opened this issue Feb 3, 2021 · 3 comments · May be fixed by #21

Comments

@wbk
Copy link

wbk commented Feb 3, 2021

Example

Source

const cacheManager = require('cache-manager');
const redisStore = require('cache-manager-ioredis');
const Redis = require('ioredis');

const redis = new Redis();

const cache = cacheManager.caching({
    store: redisStore,
    redisInstance: redis,
    ttl: 123
});

async function test() {
    await cache.set('foo', 'bar');
    console.log(await cache.ttl('foo'));
} 

test().then(process.exit);

Output (Actual)

-1

Output (Expected)

123
@kodeine
Copy link

kodeine commented Mar 1, 2021

Even if i set the TTL to 10 it does not expire. I had to set it like below to make it work.

cacheManager.caching({
  store: redisStore,
  host: process.env.REDIS_HOST,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD,
  db: 0,
  ttl: +process.env.REDIS_TTL || 10,
});
await REDIS_CACHE.set(`key`, value, 10); // setting it here does not work.

@natesilva
Copy link

natesilva commented Jun 17, 2021

We're seeing the same issue. As a workaround, we were able to set a default cache value like this for cluster mode:

var redisCache = cacheManager.caching({
  store: redisStore,
  clusterConfig: {
	 (various config settings) 
	options: {
	  ttl: 600
	}  
  }
});

For non-cluster mode you'd add an options object to the redisInstance value instead of clusterConfig.

But ultimately I hope this gets fixed. We would prefer to set the TTL at the top level so it remains compatible with other cache stores.

@natesilva natesilva linked a pull request Jun 17, 2021 that will close this issue
@Tirke
Copy link

Tirke commented Aug 9, 2022

Did a rewrite of this package with top level ttl used by external Redis instance here: https://www.npmjs.com/package/@tirke/node-cache-manager-ioredis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants