question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ioredis cache not expiring

See original GitHub issue

ioredis 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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
luincommented, Jan 24, 2022

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.

1reaction
luincommented, Jan 24, 2022

Oh I see. client.set(room,[],'EX' here since ioredis flats arguments, so the [] will be omitted. You need to provide a valid value ex client.set(room, 'anyvalue', 'EX', 24 * 3600).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found