langchain_community.storage.redis.RedisStore¶

class langchain_community.storage.redis.RedisStore(*, client: Any = None, redis_url: Optional[str] = None, client_kwargs: Optional[dict] = None, ttl: Optional[int] = None, namespace: Optional[str] = None)[source]¶

BaseStore implementation using Redis as the underlying store.

Examples

Create a RedisStore instance and perform operations on it:

# Instantiate the RedisStore with a Redis connection
from langchain_community.storage import RedisStore
from langchain_community.utilities.redis import get_client

client = get_client('redis://localhost:6379')
redis_store = RedisStore(client)

# Set values for keys
redis_store.mset([("key1", b"value1"), ("key2", b"value2")])

# Get values for keys
values = redis_store.mget(["key1", "key2"])
# [b"value1", b"value2"]

# Delete keys
redis_store.mdelete(["key1"])

# Iterate over keys
for key in redis_store.yield_keys():
    print(key)

Initialize the RedisStore with a Redis connection.

Must provide either a Redis client or a redis_url with optional client_kwargs.

Parameters
  • client – A Redis connection instance

  • redis_url – redis url

  • client_kwargs – Keyword arguments to pass to the Redis client

  • ttl – time to expire keys in seconds if provided, if None keys will never expire

  • namespace – if provided, all keys will be prefixed with this namespace

Methods

__init__(*[, client, redis_url, ...])

Initialize the RedisStore with a Redis connection.

mdelete(keys)

Delete the given keys.

mget(keys)

Get the values associated with the given keys.

mset(key_value_pairs)

Set the given key-value pairs.

yield_keys(*[, prefix])

Yield keys in the store.

__init__(*, client: Any = None, redis_url: Optional[str] = None, client_kwargs: Optional[dict] = None, ttl: Optional[int] = None, namespace: Optional[str] = None) None[source]¶

Initialize the RedisStore with a Redis connection.

Must provide either a Redis client or a redis_url with optional client_kwargs.

Parameters
  • client – A Redis connection instance

  • redis_url – redis url

  • client_kwargs – Keyword arguments to pass to the Redis client

  • ttl – time to expire keys in seconds if provided, if None keys will never expire

  • namespace – if provided, all keys will be prefixed with this namespace

mdelete(keys: Sequence[str]) None[source]¶

Delete the given keys.

mget(keys: Sequence[str]) List[Optional[bytes]][source]¶

Get the values associated with the given keys.

mset(key_value_pairs: Sequence[Tuple[str, bytes]]) None[source]¶

Set the given key-value pairs.

yield_keys(*, prefix: Optional[str] = None) Iterator[str][source]¶

Yield keys in the store.

Examples using RedisStore¶