Package: redis-sort-queue
redis-sort-queue is a priority queue for easy use on redisInstallationThe easiest way to install the redis-sort-queue package is either via
pip:$ pip install redis-sort-queueor manually by downloading the source and run the setup.py script:$ python setup.py installExamplesWe have put some self-explanatory examples in theexamplesdirectory, but here is a quick example on how to get started. Assuming
the installation was successful, you can import the redis-sort-queue
package like this:Then, create an instance ofRedisQueue:fromredis_sort_queueimportRedisQueuequeue=RedisQueue('name_queue')queue.push(100,"element1",1,"element2")element=queue.pop()You can usedatetimeas priority :fromredis_sort_queueimportRedisQueuefromdatetimeimportdatetimequeue=RedisQueue('name_queue')queue.push(datetime.now(),"element1",1,"element2")If you want to use multiple queues you must create an instance ofCollectionQueues:fromredis_sort_queueimportRedisQueue,CollectionQueuesqueue1=RedisQueue('A')queue2=RedisQueue('B')queue1.push(100,"E",1,"L")queue2.push(101,"T")collection=CollectionQueues()queue3=collection.intersect_queues('intersect1',['A','B'])If you want to use pool connectionConnectionPool:fromredis_sort_queueimportRedisQueue,CollectionQueues,ConnectionPoolpool=ConnectionPool(host='127.0.0.1',port=6379)queue1=RedisQueue('A',connection_pool=pool)queue2=RedisQueue('B',connection_pool=pool)queue1.push(100,"E",1,"L")queue2.push(101,"T",datetime.now(),10)collection=CollectionQueues(connection_pool=pool)queue3=collection.intersect_queues('intersect1',['A','B'])element=queue.pop()API libraryMethods defined here:cleanpython clean(self)Delete all values in queuecountcount(self)Return the number of elements in the queuecount_lexcount_lex(self,min,max)Return the number of items in the queue between the lexicographical
rangeminandmax.count_prioritycount_priority(self,min,max)Returns the number of elements in the queue with a score betweenminandmax.incr_prioritypython incr_priority(self, value, amount=1)Increment the score ofvaluein queue byamountlistlist(self,start=0,end=-1,desc=False,withscores=False,score_cast_func=typefloat)Return a range of values from queue betweenstartandendsorted
in ascending order.startandendcan be negative, indicating the end of the range.desca boolean indicating whether to sort the results descendinglywithscoresindicates to return the scores along with the values. The
return type is a list of (value, score) pairsscore_cast_funca callable used to cast the score return valuelist_by_lexlist_by_lex(self,min,max,start=None,num=None)Return the lexicographical range of values from sorted queue betweenminandmax.Ifstartandnumare specified, then return a slice of the
range.list_by_prioritylist_by_priority(self,min,max,start=None,num=None,withscores=False,score_cast_func=<type'float'>)Return the lexicographical range of values from sorted queue betweenminandmax.Ifstartandnumare specified, then return a slice of the
range.poppop(self,desc=False)Remove the first membervaluesfrom queue ordereddescpushpush(self,*args,**kwargs)Set any number of score, element-name pairs to the queue. Pairs can be
specified in two ways:As *args, in the form of: score1, name1, score2, name2, …The following example would add two values to the queue: redis.push(
1.1, ‘name1’, 2.2, ‘name2’)removeremove(self,*values)Remove member values from queue