A module that combines the use of redis in-built data types to build a unique queue for processing and expiry.
Project description
redis-unique-queue
A module that combines the use of redis in-built data types to build a unique queue for processing and expiry.
Usage
Items are put on the queue with an optional key. A duplicate key cannot be added until either: - the previous key that was added has been fully processed. - expiry_in_seconds have passed.
Examples
import time
import redis
import ruqueue
expiry_in_seconds = 1
conn = redis.Redis()
uqueue = ruqueue.Queue(redis_conn=conn, expiry_in_seconds=expiry_in_seconds)
uqueue.put(100)
print("Expected size 1:", uqueue.qsize())
uqueue.put(100) # not added again
print("Expected size 1:", uqueue.qsize())
uqueue.put(200) # not added again
print("Expected size 2:", uqueue.qsize())
# get an item
print("Expected item 100:", uqueue.get())
# go past expiry seconds to test
time.sleep(expiry_in_seconds)
# item 100 has expired
print(
"Items that expired:", uqueue.clear_expired()
) # [100] -> a list of items that expires
print("Expected size 1:", uqueue.qsize())
print("Expected item 200:", uqueue.get())
# we have finished handling 200
uqueue.task_done(200)
print("Expected size 0:", uqueue.qsize())
print("Expected item None:", uqueue.get())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redis-unique-queue-0.0.2.tar.gz
.
File metadata
- Download URL: redis-unique-queue-0.0.2.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 682fa5bf99d8cb14b792b622f9f3f4e6482ba48d1d71f0eaad7012bba2e59453 |
|
MD5 | c08999937e66ec54fab03819b1d5db66 |
|
BLAKE2b-256 | 4fd7508b313f346905d035d3eae02436914e4e1d6e3868fc48ecd80dc87fb3d6 |
File details
Details for the file redis_unique_queue-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: redis_unique_queue-0.0.2-py3-none-any.whl
- Upload date:
- Size: 1.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcdb443796208d68c128a55d8770c4d298568125ae6a859c0a1a08214a5c9995 |
|
MD5 | 86a87ef18ddc298eacd7f6ddd8c38102 |
|
BLAKE2b-256 | d7fae5ee0c27ae780456ff53f95aff1c9f7bbd27162b5790275b59b58ab54978 |