RedisStore#

Synchronous key-value store with optional vector search, backed by Redis.

Synchronous Redis store implementation.

class AsyncRedisStore(redis_url=None, *, redis_client=None, index=None, connection_args=None, ttl=None, cluster_mode=None, store_prefix='store', vector_prefix='store_vectors')[source]#

Bases: BaseRedisStore[Redis, AsyncSearchIndex], AsyncBatchedBaseStore

Async Redis store with optional vector search.

Supports standard Redis URLs (redis://), SSL (rediss://), and Sentinel URLs (redis+sentinel://host:26379/service_name/db).

Initialize store with Redis connection and optional index config.

Parameters:
  • redis_url (Optional[str])

  • redis_client (Optional[AsyncRedis])

  • index (Optional[IndexConfig])

  • connection_args (Optional[dict[str, Any]])

  • ttl (Optional[TTLConfig])

  • cluster_mode (bool | None)

  • store_prefix (str)

  • vector_prefix (str)

classmethod from_conn_string(conn_string, *, index=None, ttl=None, store_prefix='store', vector_prefix='store_vectors')[source]#

Create store from Redis connection string.

Parameters:
  • conn_string (str)

  • index (IndexConfig | None)

  • ttl (TTLConfig | None)

  • store_prefix (str)

  • vector_prefix (str)

Return type:

AsyncIterator[AsyncRedisStore]

async abatch(ops)[source]#

Execute batch of operations asynchronously.

Parameters:

ops (Iterable[GetOp | SearchOp | PutOp | ListNamespacesOp])

Return type:

list[Item | list[Item] | list[SearchItem] | list[tuple[str, …]] | None]

batch(ops)[source]#

Execute batch of operations synchronously.

Parameters:
  • ops (Iterable[GetOp | SearchOp | PutOp | ListNamespacesOp]) – Operations to execute in batch

  • self (AsyncRedisStore)

Returns:

Results from batch execution

Raises:

asyncio.InvalidStateError – If called from the main event loop

Return type:

list[Item | list[Item] | list[SearchItem] | list[tuple[str, …]] | None]

configure_client(redis_url=None, redis_client=None, connection_args=None)[source]#

Configure the Redis client.

Supports standard Redis URLs (redis://), SSL (rediss://), and Sentinel URLs (redis+sentinel://host:26379/service_name/db).

Parameters:
  • redis_url (str | None)

  • redis_client (Redis | None)

  • connection_args (dict[str, Any] | None)

Return type:

None

create_indexes()[source]#

Create async indices.

Return type:

None

async setup()[source]#

Initialize store indices.

Return type:

None

async start_ttl_sweeper(_sweep_interval_minutes=None)[source]#

Start TTL sweeper.

This is a no-op with Redis native TTL, but kept for API compatibility. Redis automatically removes expired keys.

Parameters:

_sweep_interval_minutes (int | None) – Ignored parameter, kept for API compatibility

Return type:

None

async stop_ttl_sweeper(_timeout=None)[source]#

Stop TTL sweeper.

This is a no-op with Redis native TTL, but kept for API compatibility.

Parameters:

_timeout (float | None) – Ignored parameter, kept for API compatibility

Returns:

Always True as there’s no sweeper to stop

Return type:

bool

async sweep_ttl()[source]#

Clean up any remaining expired items.

This is not needed with Redis native TTL, but kept for API compatibility. Redis automatically removes expired keys.

Returns:

Always returns 0 as Redis handles expiration automatically

Return type:

int

cluster_mode: bool | None = None#
store_index: AsyncSearchIndex#
supports_ttl: bool = True#
ttl_config: TTLConfig | None = None#
vector_index: AsyncSearchIndex#
class RedisStore(conn, *, index=None, ttl=None, cluster_mode=None, store_prefix='store', vector_prefix='store_vectors')[source]#

Bases: BaseStore, BaseRedisStore[Redis, SearchIndex]

Redis-backed store with optional vector search.

Provides synchronous operations for storing and retrieving data with optional vector similarity search support.

Supports standard Redis URLs (redis://), SSL (rediss://), and Sentinel URLs (redis+sentinel://host:26379/service_name/db).

Parameters:
  • conn (Redis)

  • index (Optional[IndexConfig])

  • ttl (Optional[TTLConfig])

  • cluster_mode (bool | None)

  • store_prefix (str)

  • vector_prefix (str)

classmethod from_conn_string(conn_string, *, index=None, ttl=None, store_prefix='store', vector_prefix='store_vectors')[source]#

Create store from Redis connection string.

Parameters:
  • conn_string (str)

  • index (IndexConfig | None)

  • ttl (TTLConfig | None)

  • store_prefix (str)

  • vector_prefix (str)

Return type:

Iterator[RedisStore]

async abatch(ops)[source]#

Execute batch of operations asynchronously.

Parameters:

ops (Iterable[GetOp | SearchOp | PutOp | ListNamespacesOp])

Return type:

list[Item | list[Item] | list[SearchItem] | list[tuple[str, …]] | None]

batch(ops)[source]#

Execute batch of operations.

Parameters:

ops (Iterable[GetOp | SearchOp | PutOp | ListNamespacesOp])

Return type:

list[Item | list[Item] | list[SearchItem] | list[tuple[str, …]] | None]

setup()[source]#

Initialize store indices.

Return type:

None

supports_ttl: bool = True#
ttl_config: TTLConfig | None = None#
class BaseRedisStore(conn, *, index=None, ttl=None, cluster_mode=None, store_prefix='store', vector_prefix='store_vectors')[source]#

Bases: Generic[RedisClientType, IndexType]

Base Redis implementation for persistent key-value store with optional vector search.

Initialize store with Redis connection and optional index config.

Parameters:
  • conn (RedisClientType) – Redis client connection

  • index (Optional[IndexConfig]) – Optional index configuration for vector search

  • ttl (Optional[TTLConfig]) – Optional TTL configuration

  • cluster_mode (bool | None) – Optional cluster mode setting (None = auto-detect)

  • store_prefix (str) – Prefix for store keys (default: “store”)

  • vector_prefix (str) – Prefix for vector keys (default: “store_vectors”)

async aset_client_info()[source]#

Set client info for Redis monitoring asynchronously.

Return type:

None

set_client_info()[source]#

Set client info for Redis monitoring.

Return type:

None

start_ttl_sweeper(_sweep_interval_minutes=None)[source]#

Start TTL sweeper.

This is a no-op with Redis native TTL, but kept for API compatibility. Redis automatically removes expired keys.

Parameters:

_sweep_interval_minutes (int | None) – Ignored parameter, kept for API compatibility

Return type:

None

stop_ttl_sweeper(_timeout=None)[source]#

Stop TTL sweeper.

This is a no-op with Redis native TTL, but kept for API compatibility.

Parameters:

_timeout (float | None) – Ignored parameter, kept for API compatibility

Returns:

Always True as there’s no sweeper to stop

Return type:

bool

sweep_ttl()[source]#

Clean up any remaining expired items.

This is not needed with Redis native TTL, but kept for API compatibility. Redis automatically removes expired keys.

Returns:

Always returns 0 as Redis handles expiration automatically

Return type:

int

SCHEMAS = [{'fields': [{'name': 'prefix', 'type': 'text'}, {'name': 'key', 'type': 'tag'}, {'name': 'created_at', 'type': 'numeric'}, {'name': 'updated_at', 'type': 'numeric'}, {'name': 'ttl_minutes', 'type': 'numeric'}, {'name': 'expires_at', 'type': 'numeric'}], 'index': {'name': 'store', 'prefix': 'store:', 'storage_type': 'json'}}, {'fields': [{'name': 'prefix', 'type': 'text'}, {'name': 'key', 'type': 'tag'}, {'name': 'field_name', 'type': 'tag'}, {'name': 'embedding', 'type': 'vector'}, {'name': 'created_at', 'type': 'numeric'}, {'name': 'updated_at', 'type': 'numeric'}, {'name': 'ttl_minutes', 'type': 'numeric'}, {'name': 'expires_at', 'type': 'numeric'}], 'index': {'name': 'store_vectors', 'prefix': 'store_vectors:', 'storage_type': 'json'}}]#
cluster_mode: bool | None = None#
store_index: IndexType#
supports_ttl: bool = True#
ttl_config: TTLConfig | None = None#
vector_index: IndexType#