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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With