ConsulBackend
Consul.io K/V store backend for Celery.
Attributes
| Attribute | Type | Description |
|---|---|---|
| consul | module = consul | The consul module or client library used to interface with the Consul K/V store. |
| supports_autoexpire | boolean = true | Boolean flag indicating that this backend supports automatic expiration of keys via Consul sessions. |
| consistency | string = "consistent" | The consistency mode used for Consul client read operations, defaulting to 'consistent'. |
| path | string = null | A prefix or virtual host string prepended to all keys stored in the Consul K/V store. |
Constructor
Signature
def ConsulBackend(
*args: any,
**kwargs: any
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| *args | any | Variable length argument list passed to the parent KeyValueStoreBackend class. |
| **kwargs | any | Arbitrary keyword arguments passed to the parent KeyValueStoreBackend class. |
Methods
client()
@classmethod
def client() - > consul.Consul
Returns a Consul client instance, either reusing a persistent connection or creating a new one based on configuration.
Returns
| Type | Description |
|---|---|
consul.Consul | A configured Consul client ready for K/V operations. |
get()
@classmethod
def get(
key: string
) - > bytes|null
Retrieves the value associated with a specific key from the Consul K/V store.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The identifier for the data to be retrieved. |
Returns
| Type | Description |
|---|---|
| `bytes | null` |
mget()
@classmethod
def mget(
keys: list
) - > generator
Fetches multiple values from the store by iterating through a list of provided keys.
Parameters
| Name | Type | Description |
|---|---|---|
| keys | list | A collection of key strings to look up in the store. |
Returns
| Type | Description |
|---|---|
generator | A generator yielding the values corresponding to the requested keys in order. |
set()
@classmethod
def set(
key: string,
value: bytes|string
) - > boolean
Set a key in Consul. Before creating the key it will create a session inside Consul where it creates a session with a TTL. The key created afterwards will reference to the session's ID. If the session expires it will remove the key so that results can auto expire from the K/V store
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The identifier under which the value will be stored. |
| value | `bytes | string` |
Returns
| Type | Description |
|---|---|
boolean | True if the key-value pair was successfully written and associated with the session. |
delete()
@classmethod
def delete(
key: string
) - > boolean
Removes a specific key and its associated data from the Consul K/V store.
Parameters
| Name | Type | Description |
|---|---|---|
| key | string | The identifier of the key to be deleted. |
Returns
| Type | Description |
|---|---|
boolean | Indicates whether the deletion operation was acknowledged by the server. |