# 使用Redis实现延时任务(二)
前提 前一篇文章通过 Redis 的有序集合 Sorted Set 和调度框架 Quartz 实例一版简单的延时任务,但是有两个相对重要的问题没有解决: 分片。 监控。 这篇文章的内容就是要完善这两个方面的功能。前置文章: 使用Redis实现延时任务(一) 。 为什么需要分片 这里重新贴一下查询脚本 dequeue.lua 的内容: -- 参考jesque的部分Lua脚本实现 local zset_key = KEYS[1] local hash_key = KEYS[2] local min_score = ARGV[1] local max_score = ARGV[2] local offset = ARGV[3] local limit = ARGV[4] -- TYPE命令的返回结果是{'ok':'zset'}这样子,这里利用next做一轮迭代 local status, type = next(redis.call('TYPE', zset_key)) if status ~= nil and status == 'ok' then if type == 'zset' then local list = redis.call('ZREVRANGEBYSCORE', zset_key, max_score, min_score, 'LIMIT', offset,