[ACCEPTED]-Delayed execution / scheduling with Redis?-delayed-execution
If you want to do scheduling with redis, i 7 would suggest using sorted set (the z*) commands:
what 6 you can do is something like this:
ZADD jobs <unix timestamp of when you want the job to run> <job identifier>
ZADD jobs 1291348355
Then, every 5 so often (up to every second) you can pull 4 scheduled jobs that should run (or should 3 have run by now):
ZRANGEBYSCORE jobs -inf, <current unix timestamp>
Boom, you got your jobs 2 to run. Of course, make sure to delete done 1 jobs from the sorted set.
You can work with a ring of multiple LISTs 10 that have a time component in their name. As 9 time component you can take the current 8 second (0-59).
You always add tasks to the 7 list for the current second. To get the 6 jobs you do a BLPOP (with low timeout) only 5 on those lists where it is guaranteed, that 4 the content is older than the given number 3 of seconds.
If you work from multiple hosts 2 you have to take care, that the clocks are 1 in sync (NTP).
More Related questions