Skip to main content

ConsulBackend

Consul.io K/V store backend for Celery.

Attributes​

AttributeTypeDescription
consulmodule = consulThe consul module or client library used to interface with the Consul K/V store.
supports_autoexpireboolean = trueBoolean flag indicating that this backend supports automatic expiration of keys via Consul sessions.
consistencystring = "consistent"The consistency mode used for Consul client read operations, defaulting to 'consistent'.
pathstring = nullA 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​

NameTypeDescription
*argsanyVariable length argument list passed to the parent KeyValueStoreBackend class.
**kwargsanyArbitrary 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​

TypeDescription
consul.ConsulA 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​

NameTypeDescription
keystringThe identifier for the data to be retrieved.

Returns​

TypeDescription
`bytesnull`

mget()​

@classmethod
def mget(
keys: list
) - > generator

Fetches multiple values from the store by iterating through a list of provided keys.

Parameters​

NameTypeDescription
keyslistA collection of key strings to look up in the store.

Returns​

TypeDescription
generatorA 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​

NameTypeDescription
keystringThe identifier under which the value will be stored.
value`bytesstring`

Returns​

TypeDescription
booleanTrue 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​

NameTypeDescription
keystringThe identifier of the key to be deleted.

Returns​

TypeDescription
booleanIndicates whether the deletion operation was acknowledged by the server.