ioredis cache not expiring
See original GitHub issueioredis cache not expiring
I’m building a chatroom cache which should persist for 2 min in redis database, but even after using expireat method cache does not get cleared.
This is my code for storing the cache
Code
//check whether room already exists or not
//if not set certain expiry timestamp
const setMessage = async(room,from,message)=>{
//check whether room exists or not
client.lrange(room,0,-1,async(err,replies)=>{
console.log(err,replies)
if(replies.length==0)
{
const when = 24*60*60
client.set(room,[],'EX',when,(err,ans)=>{//here in seconds
console.log(`setting expiry at ${ new Date(Date.now() + when*1000)}`) //here in milliseconds
})
}
})
await client.rpush(room,`${from}:${message}`);
}
Expected behavior This snippet of code should delete the key(room) from redis cache after completion of 24 hrs. But as a result, cache is persisted even after the completion of 24 hrs.
Dependencies “express”: “^4.17.1”, “ioredis”: “^4.28.2”
Is there any way to figure this out?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Nodejs IOREDIS: how to set expire time for a key?
It's documented redis.set('key', 100, 'ex', 10). Where EX and 10 stands for 10 seconds. If you want to use milliseconds, replace EX with...
Read more >how to set expire time · Issue #1000 · redis/node-redis - GitHub
Each command would have to be checked and manipulated. Instead, a new feature to add hooks could solve that. This is not a...
Read more >EXPIRE - Redis
The EXPIRE command supports a set of options: NX -- Set expiry only when the key has no expiry; XX -- Set expiry...
Read more >ioredis-cache - npm
ioredis -cache. Compact redis cache using ioredis. Features. Store/retrieve/expire cache; Compatible with redis incr , hincrby ,.
Read more >Redis Keys Expire — Things you need to know. | by Abhimanyu
Whenever we create a key in Redis, this key is created without any timeout or expiration value. So they live forever in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No problem! If you are on a macOS can try out a GUI tool ex https://getmedis.com/ to inspect the TTL & value of keys easier.
Oh I see.
client.set(room,[],'EX'
here since ioredis flats arguments, so the[]
will be omitted. You need to provide a valid value exclient.set(room, 'anyvalue', 'EX', 24 * 3600)
.