langchain.utilities.redis.get_client¶
langchain.utilities.redis.get_client(redis_url: str, **kwargs: Any) → RedisType[source]¶
Get a redis client from the connection url given. This helper accepts
urls for Redis server (TCP with/without TLS or UnixSocket) as well as
Redis Sentinel connections.
Redis Cluster is not supported.
Before creating a connection the existence of the database driver is checked
an and ValueError raised otherwise
To use, you should have the redis python package installed.
Example
from langchain.utilities.redis import get_client
redis_client = get_client(
    redis_url="redis://username:password@localhost:6379"
    index_name="my-index",
    embedding_function=embeddings.embed_query,
)
To use a redis replication setup with multiple redis server and redis sentinels
set “redis_url” to “redis+sentinel://” scheme. With this url format a path is
needed holding the name of the redis service within the sentinels to get the
correct redis server connection. The default service name is “mymaster”. The
optional second part of the path is the redis db number to connect to.
An optional username or password is used for booth connections to the rediserver
and the sentinel, different passwords for server and sentinel are not supported.
And as another constraint only one sentinel instance can be given:
Example
from langchain.utilities.redis import get_client
redis_client = get_client(
    redis_url="redis+sentinel://username:password@sentinelhost:26379/mymaster/0"
    index_name="my-index",
    embedding_function=embeddings.embed_query,
)