1

I am using Nodejs and "redis" for a pub sub to hear for expired Events.

In default its working just fine but when I switch to a different selected db it just does not get subscribe but I am seeing the setex working properly

Here is my code:-

const redis = require("redis");

const pub = redis.createClient({ url: process.env.REDIS_URL });
pub.connect();
pub.configSet("notify-keyspace-events", "Ex");
pub.select(4).then(() => {
   pub.setEx('mm', 5, "lopl")

})


const sub = pub.duplicate();
sub.connect()
sub.select(4).then(() => {
   sub.subscribe("__keyevent@0__:expired", (key) => {
      console.log("key=> ", key)
   })
})

1 Answers1

0

I got the answer, sub.subscribe("keyevent@0:expired)

in this line that 0 describe the db number change it to your desired and you are good to go

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 20 '22 at 04:44