I’ve been encountering this problem with ioredis where I have created a key and set expiry for that key. My code looks something like this
let temp1 = acct.limit;
let txn = array.length;
let cache = new ioredis(); // note that this is not the exact code snippet
let ttl = txn / temp1;
cache.set('key', true, Math.ceil(ttl));
The problem that I encountered is that sometimes the ttl
is a positive number and sometimes a negative number. Thus, leading to the belief that maybe -1 is for an unlimited ttl. But upon further research and also trial and error anything less than or equal to 0 expires immediately. So my question really is, why some keys don’t expire even with a set ttl?
2
Answers
Redis EXPIRE for a key is set in ttl seconds. So anything less than or equal to 0 for the ttl value will expire the keys immediately. The question is not clear because you have already explained that anything less than or equal to 0 will make the key expire immediately.
TTL
command returns three types of responses;