Search code examples
schedulingredisdelayed-execution

Delayed execution / scheduling with Redis?


Any tricks to do delayed task execution (i.e. scheduling) based on Redis?

Perhaps some clever way to delay BLPOP for a given number of seconds?..


Solution

  • You can work with a ring of multiple LISTs that have a time component in their name. As time component you can take the current second (0-59).

    You always add tasks to the list for the current second. To get the jobs you do a BLPOP (with low timeout) only on those lists where it is guaranteed, that the content is older than the given number of seconds.

    If you work from multiple hosts you have to take care, that the clocks are in sync (NTP).