Skip to main content

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.

The unique queue creates 3 datastructures to ensure the keys are unique. To ensure the keys don't linger after usage, all commands reset the ttl on the datastructures. Examples

    import time

    import redis

    import redis_unique_queue

    expiry_in_seconds = 1
    conn = redis.Redis()
    uqueue = redis_unique_queue.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())

    print("Expected item 100:", uqueue.get()) # get an item


    time.sleep(expiry_in_seconds) # go past expiry seconds to test

    # 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


Download files

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

Source Distribution

redis_unique_queue-0.0.5.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_unique_queue-0.0.5-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file redis_unique_queue-0.0.5.tar.gz.

File metadata

  • Download URL: redis_unique_queue-0.0.5.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for redis_unique_queue-0.0.5.tar.gz
Algorithm Hash digest
SHA256 b006bf187da454e2d9a695717ea72eb9a23fbbd1f528f7c3ba17386db198eed9
MD5 e48ab829cbf7e4b49977bb07af08e492
BLAKE2b-256 18298c06a5059d1551ce081801d39648069f5a2dbea453aef33d11625bdd766d

See more details on using hashes here.

File details

Details for the file redis_unique_queue-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_unique_queue-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 327c3b2602d12b3b93b790f9ebceb0002637c4df36b9e2959452c1ee299d1f69
MD5 8f059abb31ee64610726a431fe3b22a9
BLAKE2b-256 93d804d0086bc016181ec5978202d07f771f12b183403209770255721fafcd6d

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