简单的redis工作队列,添加了一些特性(优先级,一次弹出多个项目)
rpq的Python项目详细描述
redis priority queue是一个类似于Redis lists的简单工作队列,添加了以下内容 功能:
- 可以添加具有优先级的项(介于-9007199254740992和 9007199254740992)
- 队列将自动消除重复(重复项将作废 推动它们时)
- 可以同时从队列中弹出多个项目
- 很容易看出 每个队列中都有许多项目
redis优先级队列基于Redis sorted sets和所有排序集 命令可以与此项目一起使用。
基本用法
bash示例
-- Generic redis-cli --eval src/redis-priority-queue.lua null null , [push|pop|peek|count] my_list (arg1, arg2...) -- Push an item redis-cli --eval src/redis-priority-queue.lua null null , push my_super_list my_item -- Pop an item redis-cli --eval src/redis-priority-queue.lua null null , pop my_super_list
push:推送队列中的项目
使用量
push my_list item [(int) priority (default: 100)]
示例
-- Push an item with the default priority (100) push my_super_list my_item -- Push an item with a priority of 200 push my_super_list my_item 200
返回
输出类似于ZADD
pop:从队列中弹出项目
用法
pop my_list [(string) asc/desc (default: 'desc')] [(int) numer_of_items (default: 1')]
示例
-- Pop 1 item ordered by descending priority pop my_super_list -- Pop 1 item ordered by ascending priority pop my_super_list asc -- Pop 5 items ordered by descending priority pop my_super_list desc 5
返回
输出类似于 ZRANGEBYSCORE
peek:从列表中查看一组项
别名:list,view
用法
与pop相同,但不会从列表中删除项。
count:统计队列中的项目
别名:size
用法
count my_list [(int) priority_min] [(int) priority_max]
示例
-- Count all items from the list count my_super_list -- Count all items with a priority between 1 and 1110 count my_super_list 1 1110
返回
输出类似于ZCOUNT
队列监视
可以使用python脚本轻松监视队列 src/queue_monitor.py
要使用队列监视器,需要确保安装了python并使用 以下命令:
# Installation pip3 install rpq # Usage rpq_monitor
使用示例
# Basic usage rpq_monitor -H [host] -p [port] (-a [auth] -n [dbnum]) +-------------------+-------+-----------+----------+ | Queue name | Total | Up to 100 | From 101 | +-------------------+-------+-----------+----------+ | book_orders | 44 | 12 | 32 | | book_recycle | 223 | 123 | 100 | | book_returns | 13 | 13 | 0 | | late_fees_pending | 112 | 56 | 56 | | new_books | 1,144 | 1,120 | 24 | +-------------------+-------+-----------+----------+ # Specify your own groups rpq_monitor -H [host] -p [port] (-a [auth] -n [dbnum]) -s "[[0, 1000], [1001, 2000], [2001, 3000]]" +-------------------+-------+------------+----------------+----------------+ | Queue name | Total | 0 to 1,000 | 1,001 to 2,000 | 2,001 to 3,000 | +-------------------+-------+------------+----------------+----------------+ | book_orders | 44 | 24 | 9 | 11 | | book_recycle | 223 | 127 | 40 | 56 | | book_returns | 13 | 13 | 0 | 0 | | late_fees_pending | 112 | 58 | 13 | 41 | | new_books | 1,144 | 1,142 | 2 | 0 | +-------------------+-------+------------+----------------+----------------+