rocksq.nonblocking
- class rocksq.nonblocking.PersistentQueueWithCapacity(path, max_elements=1000000000, max_inflight_ops=1000)
A persistent queue with a fixed capacity. This is a non-blocking implementation. All methods return the future-like object
Response
which must be used to get the actual response.- Parameters:
path (str) – The path to the queue.
max_elements (int) – The maximum number of elements the queue can hold. Default to
1_000_000_000
.max_inflight_ops (int) – The maximum number of inflight operations. If the number of inflight operations reached its limit, further ops are blocked until the capacity is available. Default to
1_000
.
- Raises:
PyRuntimeError – If the queue could not be created.
- disk_size
Returns the disk size of the queue.
- Raises:
PyRuntimeError –
- Returns:
The future-like object which must be used to get the actual response. For the size operation, the response object is useful to call for
is_ready()
,try_get()
andget()
.- Return type:
- inflight_ops
- len
Returns the length of the queue.
- Raises:
PyRuntimeError – If the method fails.
- Returns:
The future-like object which must be used to get the actual response. For the length operation, the response object is useful to call for
is_ready()
,try_get()
andget()
.- Return type:
- payload_size
Returns the payload size of the queue.
- Raises:
PyRuntimeError –
- Returns:
The future-like object which must be used to get the actual response. For the size operation, the response object is useful to call for
is_ready()
,try_get()
andget()
.- Return type:
- pop(max_elements=1, no_gil=True)
Retrieves items from the queue.
GIL: the method can optionally be called without the GIL.
- Parameters:
max_elements (int) – The maximum number of elements to retrieve. Default to
1
.no_gil (bool) – If True, the method will be called without the GIL. Default is
True
.
- Raises:
PyRuntimeError – If the method fails.
- Returns:
The future-like object which must be used to get the actual response. For the pop operation, the response object is useful to call for
is_ready()
,try_get()
andget()
.- Return type:
- push(items, no_gil=True)
Adds items to the queue.
GIL: the method can optionally be called without the GIL.
- Parameters:
items (list of bytes) – The items to add to the queue.
no_gil (bool) – If True, the method will be called without the GIL. Default is
True
.
- Raises:
PyRuntimeError – If the method fails.
- Returns:
The future-like object which must be used to get the actual response. For the push operation, the response object is only useful to call for is_ready().
- Return type:
- class rocksq.nonblocking.Response
- get()
Returns the response in a blocking way.
GIL: the method releases the GIL
- Raises:
PyRuntimeError – If the method fails.
- Returns:
The response when it is ready.
- Return type:
- is_ready
Checks if the response is ready.
- Returns:
True
if the response is ready,False
otherwise.- Return type:
bool
- try_get()
Returns the response if it is ready.
- Raises:
PyRuntimeError – If the method fails.
- Returns:
ResponseVariant
– The response if it is ready,None
– otherwise.
- class rocksq.nonblocking.ResponseVariant
A response variant containing the actual data for push, pop, size and length operations. The object is created only by the library, there is no public constructor.
- data
Returns the data for the
pop()
operation.- Raises:
PyRuntimeError – If the method fails.
- Returns:
list of bytes – The data for the
pop()
operation if the operation was successful,None
– if the future doesn’t represent thepop()
operation.
- len
Returns the length of the queue.
- Raises:
PyRuntimeError – If the method fails.
- Returns:
int
– The length of the queue if the operation was successful,None
– if the future doesn’t represent thelength()
operation.
- size
Returns the size of the queue.
- Raises:
PyRuntimeError – If the method fails.
- Returns:
int
– The size of the queue if the operation was successful,None
– if the future doesn’t represent thesize()
operation.