使用Redis延迟执行/调度? [英] Delayed execution / scheduling with Redis?

查看:143
本文介绍了使用Redis延迟执行/调度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以基于Redis延迟任务执行(即计划)?

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

也许有一些聪明的方法可以将BLPOP延迟给定的秒数?..

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

推荐答案

您可以使用多个LIST组成的环,这些LIST的名称带有时间成分.作为时间成分,您可以选择当前秒(0-59).

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

您总是将任务添加到当前秒的列表中.要获得作业,您只能在保证内容早于给定秒数的那些列表上执行BLPOP(低超时).

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.

如果您在多个主机上工作,则必须注意时钟是同步的(NTP).

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

这篇关于使用Redis延迟执行/调度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆