Working with Redis queues¶
QueueHandler
and QueueListener
classes are provided to facilitate interfacing with Redis.
-
class
logutils.redis.
RedisQueueHandler
(key='python.logging', redis=None, limit=0)¶ A QueueHandler implementation which pushes pickled records to a Redis queue using a specified key.
Parameters: - key – The key to use for the queue. Defaults to “python.logging”.
- redis – If specified, this instance is used to communicate with a Redis instance.
- limit – If specified, the queue is restricted to have only this many elements.
-
enqueue
(record)¶ Enqueue a record.
The base implementation uses
put_nowait()
. You may want to override this method if you want to use blocking, timeouts or custom queue implementations.Parameters: record – The record to enqueue.
-
class
logutils.redis.
RedisQueueListener
(*handlers, **kwargs)¶ A QueueListener implementation which fetches pickled records from a Redis queue using a specified key.
Parameters: - key – The key to use for the queue. Defaults to “python.logging”.
- redis – If specified, this instance is used to communicate with a Redis instance.
-
dequeue
(block)¶ Dequeue and return a record.
-
enqueue_sentinel
()¶ Writes a sentinel to the queue to tell the listener to quit. This implementation uses
put_nowait()
. You may want to override this method if you want to use timeouts or work with custom queue implementations.