Package: fastrq
Fastrq - Queue, Stack and Priority Queue built on RedisFastrq for PHPFeaturesAbstract Queue, Deque, Capped Queue/Deque, and Overflow-able Capped Queue/DequeAbstract Stack, Capped StackAbstract Priority Queue, Capped Priority Queue and Overflow-able Capped Priority QueuePush and Pop support batch operationUsing Lua scripts to save RTT (Round Trip Time)Support getting indexes of membersSupport pushing only if a member not already inside the queueSupport pushing only if the queue already exists/not already existAll operations areatomicRequirementsRedis >=3.0.2Python 2.7 or >=3.4Installationvia pippip install fastrqor from sourcepython setup.py installUsagefromfastrq.queueimportQueue,CappedQueuefromfastrq.dequeimportDequefromfastrq.stackimportStackfromfastrq.priorityqueueimportPriorityQueue# queueq=Queue("fastrq_queue")q.push(1)q.push([2,3])q.push_ni(1)# got [3, False]. `ni` stands `not inside`q.push_ae(1)# got 4. `ae` stands `already exists`q.push_ne(1)# got False. `ne` stands `not already exist`q.ttl(10)# set the lifetime in secondsq.range(0,-1)# got ['1', '2', '3']q.range(0,1)# got ['1', '2']q.indexof_one(1);# got 0q.indexof_one(2);# got 1q.indexof_one(4);# got Noneq.indexof_many([1,2,4]);# got {1: 0, 2: 1, 4: None}# push only if the member not inside the queueq.push_ni(4)# got [4, True]q.pop()q.pop(2)q.destruct()# destruct the queuecq=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 forced out# dequedq=Deque("fastrq_deque")dq.push_front([1,2])dq.push_back([3,4])dq.pop_front()dq.pop_back()dq.push_front_ni(3)dq.push_back_ni(5)# priority queuepq=PriorityQueue("fastrq_priority_queue")pq.push({'alibaba':1})pq.push({'google':0,'microsoft':2})pq.indexof_one('google');# got 0pq.indexof_one('alibaba');# got 1pq.indexof_one('baidu');# got Nonepq.pop()pq.pop(2)pq.push_ni('ibm',4)pq.push_ni('amazon',5)# stacks=Stack("fastrq_stack")s.push([1,2,3])s.indexof_one(1);# got 2s.indexof_one(2);# got 1s.indexof_one(3);# got 0s.pop()s.push_ni(4)Data typesQueuefirst in and first outunlimited capacitysupport batch push and batch popDequeDerive from queue with more featuressupport push front and push backsupport pop front and pop backCapped Queue/DequeDerive from queue/deque with more featuresHave fixed capacityPush to a full one would failPush to one whose positions are not enough would failOverflow-able Capped Queue/DequeDerive from capped queue/deque with more featuresThe queue length would never exceed its capacityPush to an end would force out from the other end if one is fullStackLast in and First outUnlimited capacitySupport batch push and batch popCapped StackDerive from Stack with more featuresHave fixed capacityPush to a full capped stack would failPush to a capped stack whose positions are not enough would failPriority QueueThe lower the score, the higher the priorityUnlimited capacitySupport batch push and batch popCapped Priority QueueDerive from Priority Queue with more featuresHave fixed capacityPush to a full one would failPush to a capped one whose positions are not enough would failOverflow-able Capped Priority QueueDerive from Capped Priority Queue with more featuresThe queue length would never exceed its capacityPush to would force out the lowest priority if queue is full