redis_throttled_queue#

class redis_throttled_queue.AsyncThrottledQueue(*args, **kwargs)[source]#

Asyncio variant of the queue.

__init__(*args, **kwargs)[source]#

Overrides certain options because they cannot work anymore: validate_version=False, register_library=False.

async cleanup()[source]#

Asyncio variant for cleanup.

async pop(window: str | bytes | int = Ellipsis) str | bytes | None[source]#

Asyncio variant for pop.

async push(name: str, data: str | bytes, *, priority: int = 0)[source]#

Asyncio variant for push.

async classmethod register_library(redis_client: Redis)[source]#

You have to call this manually.

async size()[source]#

Asyncio variant for __len__.

async validate_version()[source]#

You have to call this manually.

enum redis_throttled_queue.Resolution(value)[source]#
Member Type:

int

Valid values are as follows:

SECOND = <Resolution.SECOND: 1>#
MINUTE = <Resolution.MINUTE: 60>#
class redis_throttled_queue.ThrottledQueue(redis_client: Redis, prefix: str, limit: int = 10, resolution=Resolution.SECOND, validate_version=True, register_library=True)[source]#

Queue system with key-based throttling implemented over Redis.

Publishers push given a key.

Consumers pop one item at a time for the first key that has not exceeded the throttling limit withing the resolution window.

__init__(redis_client: Redis, prefix: str, limit: int = 10, resolution=Resolution.SECOND, validate_version=True, register_library=True)[source]#
Parameters:
  • redis_client – An instance of StrictRedis.

  • prefix – Redis key prefix.

  • limit – Throttling limit. The queue won’t retrieve more items in the given resolution for a given key.

  • resolution – Resolution to use. This decides how many time window keys you will have in Redis.

__len__()[source]#

Get queue length. :return:

cleanup()[source]#

Cleanup all associated redis data to this queue.

classmethod ensure_supported_redis(info: dict)[source]#

Redis version validator (must be >=7). Called from __init__, if enabled.

property idle_seconds: float#

Idle time counter.

last_activity: float#
limit: int#
pop(window: str | bytes | int = Ellipsis) str | bytes | None[source]#

Pop an item, if any available.

push(name: str, data: str | bytes, *, priority: int = 0)[source]#

Push an item.

classmethod register_library(redis_client: Redis)[source]#

Registers the redis functions. Called from __init__, if enabled.

resolution: int#