valkey#
- class litestar.stores.valkey.ValkeyStore#
- Bases: - NamespacedStore- Valkey based, thread and process safe asynchronous key/value store. - __init__(valkey: Valkey, namespace: str | None | Literal[_EmptyEnum.EMPTY] = _EmptyEnum.EMPTY, handle_client_shutdown: bool = False) None#
- Initialize - ValkeyStore- Parameters:
- valkey¶ – An - valkey.asyncio.Valkeyinstance
- namespace¶ – A key prefix to simulate a namespace in valkey. If not given, defaults to - LITESTAR. Namespacing can be explicitly disabled by passing- None. This will make- delete_all()unavailable.
- handle_client_shutdown¶ – If - True, handle the shutdown of the valkey instance automatically during the store’s lifespan. Should be set to True unless the shutdown is handled externally
 
 
 - classmethod with_client(url: str = 'valkey://localhost:6379', *, db: int | None = None, port: int | None = None, username: str | None = None, password: str | None = None, namespace: str | None | Literal[_EmptyEnum.EMPTY] = _EmptyEnum.EMPTY) ValkeyStore#
- Initialize a - ValkeyStoreinstance with a new class:valkey.asyncio.Valkey instance.
 - with_namespace(namespace: str) ValkeyStore#
- Return a new - ValkeyStorewith a nested virtual key namespace. The current instances namespace will serve as a prefix for the namespace, so it can be considered the parent namespace.
 - async set(key: str, value: str | bytes, expires_in: int | timedelta | None = None) None#
- Set a value. 
 - async get(key: str, renew_for: int | timedelta | None = None) bytes | None#
- Get a value. - Parameters:
- key¶ – Key associated with the value 
- renew_for¶ – If given and the value had an initial expiry time set, renew the expiry time for - renew_forseconds. If the value has not been set with an expiry time this is a no-op. Atomicity of this step is guaranteed by using a lua script to execute fetch and renewal. If- renew_foris not given, the script will be bypassed so no overhead will occur
 
- Returns:
- The value associated with - keyif it exists and is not expired, else- None
 
 - async delete(key: str) None#
- Delete a value. - If no such key exists, this is a no-op. - Parameters:
- key¶ – Key of the value to delete 
 
 - async delete_all() None#
- Delete all stored values in the virtual key namespace. - Raises:
- ImproperlyConfiguredException – If no namespace was configured