Skip to main content

RedisKeyValueStoreClient

Redis implementation of the key-value store client.

This client persists key-value data to Redis using hash data structures for efficient storage and retrieval. Keys are mapped to values with automatic content type detection and size tracking for metadata management.

The key-value store data is stored in Redis using the following key pattern:

  • key_value_stores:{name}:items - Redis hash containing key-value pairs (values stored as binary data).
  • key_value_stores:{name}:metadata_items - Redis hash containing metadata for each key.
  • key_value_stores:{name}:metadata - Redis JSON object containing store metadata.

Values are serialized based on their type: JSON objects are stored as UTF-8 encoded JSON strings, text values as UTF-8 encoded strings, and binary data as-is. The implementation automatically handles content type detection and maintains metadata about each record including size and MIME type information.

All operations are atomic through Redis hash operations and pipeline transactions. The client supports concurrent access through Redis's built-in atomic operations for hash fields.

Hierarchy

Index

Methods

__init__

  • __init__(storage_name, storage_id, redis): None
  • Initialize a new instance.

    Preferably use the RedisKeyValueStoreClient.open class method to create a new instance.


    Parameters

    • storage_name: str
    • storage_id: str
    • redis: Redis

    Returns None

delete_value

  • async delete_value(*, key): None
  • Delete a value from the key-value store by its key.

    The backend method for the KeyValueStore.delete_value call.


    Parameters

    • keyword-onlykey: str

    Returns None

drop

  • async drop(): None
  • Drop the whole key-value store and remove all its values.

    The backend method for the KeyValueStore.drop call.


    Returns None

get_metadata

get_public_url

  • async get_public_url(*, key): str
  • Get the public URL for the given key.

    The backend method for the KeyValueStore.get_public_url call.


    Parameters

    • keyword-onlykey: str

    Returns str

get_value

iterate_keys

  • Iterate over all the existing keys in the key-value store.

    The backend method for the KeyValueStore.iterate_keys call.


    Parameters

    • optionalkeyword-onlyexclusive_start_key: str | None = None
    • optionalkeyword-onlylimit: int | None = None

    Returns AsyncIterator[KeyValueStoreRecordMetadata]

open

  • Open or create a new Redis key-value store client.

    This method attempts to open an existing key-value store from the Redis database. If a store with the specified ID or name exists, it loads the metadata from the database. If no existing store is found, a new one is created.


    Parameters

    • keyword-onlyid: str | None

      The ID of the key-value store. If not provided, a random ID will be generated.

    • keyword-onlyname: str | None

      The name of the key-value store for named (global scope) storages.

    • keyword-onlyalias: str | None

      The alias of the key-value store for unnamed (run scope) storages.

    • keyword-onlyredis: Redis

      Redis client instance.

    Returns RedisKeyValueStoreClient

purge

  • async purge(): None
  • Purge all items from the key-value store.

    The backend method for the KeyValueStore.purge call.


    Returns None

record_exists

  • async record_exists(*, key): bool
  • Check if a record with the given key exists in the key-value store.

    The backend method for the KeyValueStore.record_exists call.


    Parameters

    • keyword-onlykey: str

      The key to check for existence.

    Returns bool

set_value

  • async set_value(*, key, value, content_type): None
  • Set a value in the key-value store by its key.

    The backend method for the KeyValueStore.set_value call.


    Parameters

    • keyword-onlykey: str
    • keyword-onlyvalue: Any
    • optionalkeyword-onlycontent_type: str | None = None

    Returns None

Properties

metadata_key

metadata_key: str

Return the Redis key for the metadata of this storage.

redis

redis: Redis

Return the Redis client instance.