基于redis的队列、双向队列、优先队列和堆栈,以及众多增强版本
支持定长。向满队列PUSH会失败,向容量不足的队列PUSH同样会失败。
支持可溢出。定长队列长度超过容量限制,元素会从另一端溢出。
PUSH/POP支持批量操作
Queue
Deque
Capped Queue/Deque
容量固定
向一个满的队列PUSH会失败
向一个容量不足的队列PUSH会失败
Overflow-able Capped Queue/Deque
队列长度超过容量自动溢出
单向队列从前端溢出
双向队列从PUSH端的另一端溢出
Priority Queue
Capped Priority Queue
Overflow-able Capped Priority Queue
溢出顺序按优先级从低到高
Stack
Capped Stack
源码安装
python setup.py install
pip安装
pip install fastrq
使用
from fastrq.queue import Queue, CappedQueue from fastrq.deque import Deque from fastrq.stack import Stack from fastrq.priorityqueue import PriorityQueue # queue q = Queue("fastrq_queue") q.push(1) q.push([2, 3]) q.ttl(10) # set the lifetime in seconds q.range(0, -1) # got ['1', '2', '3'] q.range(0, 1) # got ['1', '2'] q.pop() q.pop(2) q.destruct() # destruct the queue cq = CappedQueue("fastrq_capped_queue", 3) cq.push(1) cq.push(2) cq.push([3, 4]) # got "err_qof" cq.push(3) cq.push(4) # got "err_qf" of_cq = OfCappedQueue("fastrq_of_capped_queue", 3) of_cq.push(1) of_cq.push([2, 3, 4]) # "1" would be pushed out # deque dq = Deque("fastrq_deque") dq.push_front([1, 2]) dq.push_back([3, 4]) dq.pop_front() dq.pop_back() # priority queue pq = PriorityQueue("fastrq_priority_queue") pq.push({'alibaba': 1}) pq.push({'google': 0, 'microsoft': 1}) pq.pop() pq.pop(2) # stack s = Stack("fastrq_stack") s.push([1,2,3]) s.pop()