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
.
- 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.
- 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.
- classmethod register_library(redis_client: Redis)[source]#
Registers the redis functions. Called from
__init__
, if enabled.
- resolution: int#