Delayed execution / scheduling with Redis?

后端 未结 3 1135
粉色の甜心
粉色の甜心 2020-12-15 14:17

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?..

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 14:46

    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).

提交回复
热议问题