Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can to set expire time for a redis pub/sub message

i want to set expire time to redis pub/sub messages while being published. How do i do it in nodeJS?

var redis = require('redis');

redis.createClient().publish('some channel', 'some message', function(err) {  
  if (err) {
    console.error('error publishing:', err);
  }
});

The code to pusblish a message is above. what all changes do i have to do to set expiry time for the published message.

like image 597
The-Higgs-Boson Avatar asked Sep 15 '25 00:09

The-Higgs-Boson


1 Answers

Every message expires immediately and you cannot change it. To make it work differently would require adding a cache of the messages, keeping them for a certain time after they are published and reposting them to any subscriber who subscribed after they were already published.

This is not how PubSub works in Redis. You can think of it as somewhat similar to events. Event listeners can listen to evets and event emitters can emit events. But there is no notion of expiration time of an event. Some listener either listens to it while it is emitted or not. The same is true for publishers and subscribers.

like image 93
rsp Avatar answered Sep 17 '25 14:09

rsp