Skip to main content

ordered queue for redis

Project description

redis-sort-queue is a priority queue for easy use on redis

Installation

The easiest way to install the redis-sort-queue package is either via pip:

$ pip install redis-sort-queue

or manually by downloading the source and run the setup.py script:

$ python setup.py install

Examples

We have put some self-explanatory examples in the examples directory, 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 of RedisQueue:

from redis_sort_queue import RedisQueue
queue = RedisQueue('name_queue')
queue.push(100, "element1",1, "element2")
element=queue.pop()

You can use datetime as priority :

from redis_sort_queue import RedisQueue
from datetime import datetime

queue = RedisQueue('name_queue')
queue.push(datetime.now(), "element1",1, "element2")

If you want to use multiple queues you must create an instance of CollectionQueues :

from redis_sort_queue import RedisQueue, CollectionQueues
queue1 = 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 connection ConnectionPool :

from redis_sort_queue import RedisQueue, CollectionQueues, ConnectionPool
pool = 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 library

Methods defined here:

clean python clean(self)
Delete all values in queue

count

count(self)

Return the number of elements in the queue

count_lex

count_lex(self, min, max)

Return the number of items in the queue between the lexicographical range min and max.

count_priority

count_priority(self, min, max)

Returns the number of elements in the queue with a score between min and max.

incr_priority python incr_priority(self, value, amount=1)
Increment the score of value in queue by amount

list

list(self, start=0, end=-1, desc=False, withscores=False, score_cast_func=type float)

Return a range of values from queue between start and end sorted in ascending order.

start and end can be negative, indicating the end of the range.

desc a boolean indicating whether to sort the results descendingly

withscores indicates to return the scores along with the values. The return type is a list of (value, score) pairs

score_cast_func a callable used to cast the score return value

list_by_lex

list_by_lex(self, min, max, start=None, num=None)

Return the lexicographical range of values from sorted queue between min and max.

If start and num are specified, then return a slice of the range.

list_by_priority

list_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 between min and max.

If start and num are specified, then return a slice of the range.

pop

pop(self, desc=False)

Remove the first member values from queue ordered desc

push

push(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’)

remove

remove(self, *values)

Remove member values from queue

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redis-sort-queue-1.3.3.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file redis-sort-queue-1.3.3.tar.gz.

File metadata

File hashes

Hashes for redis-sort-queue-1.3.3.tar.gz
Algorithm Hash digest
SHA256 e551667e0c267269fda1e47c6690eefffd0638432d6f662ab9c5dee376fed0ba
MD5 0758dcd3e817c6af261718ace5aeb386
BLAKE2b-256 83dfc16a10bb9b384e8246932d431d5ecd2bf817223f16ac2300b91a65dfe82a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page