NodeJS & Redis Timeout trigger from Redis

I want to make a cluster based NodeJS script that has 8 or more workers. The script when it was standalone used SetTimeout and timers were stored internally in the NodeJS script. Now I have to do something with this and I thought maybe I can use redis expiration and somehow call a function from redis on key expiration?

Can anyone show me a small example please? And another question: how reliable is this?

If you are using Redis 2.8.0+, then there are keyspace notifications. These use the existing pubsub mechanism in Redis, so you can simply subscribe to these various notifications.

You do need to make sure to enable these notifications though as they are disabled by default. You can do this by changing your redis.conf configuration file for a permanent solution, or you could enable it temporarily via the Redis CLI with something like CONFIG SET notify-keyspace-events EKx. You can also enable it from the redis module with something like:

client.config('set', 'notify-keyspace-events', 'EKx', function(err) {
  if (err) throw err;
});