mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
community[minor]: fix redis store docstring and streamline initialization code (#22730)
Thank you for contributing to LangChain! ### Description Fix the example in the docstring of redis store. Change the initilization logic and remove redundant check, enhance error message. ### Issue The example in docstring of how to use redis store was wrong.  ### Dependencies Nothing - [ ] **Add tests and docs**: If you're adding a new integration, please include 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/ If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
parent
ad101adec8
commit
ce4e29ae42
@ -18,7 +18,7 @@ class RedisStore(ByteStore):
|
|||||||
from langchain_community.utilities.redis import get_client
|
from langchain_community.utilities.redis import get_client
|
||||||
|
|
||||||
client = get_client('redis://localhost:6379')
|
client = get_client('redis://localhost:6379')
|
||||||
redis_store = RedisStore(client)
|
redis_store = RedisStore(client=client)
|
||||||
|
|
||||||
# Set values for keys
|
# Set values for keys
|
||||||
redis_store.mset([("key1", b"value1"), ("key2", b"value2")])
|
redis_store.mset([("key1", b"value1"), ("key2", b"value2")])
|
||||||
@ -64,12 +64,15 @@ class RedisStore(ByteStore):
|
|||||||
"pip install redis"
|
"pip install redis"
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
if client and redis_url or client and client_kwargs:
|
if client and (redis_url or client_kwargs):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Either a Redis client or a redis_url with optional client_kwargs "
|
"Either a Redis client or a redis_url with optional client_kwargs "
|
||||||
"must be provided, but not both."
|
"must be provided, but not both."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not client and not redis_url:
|
||||||
|
raise ValueError("Either a Redis client or a redis_url must be provided.")
|
||||||
|
|
||||||
if client:
|
if client:
|
||||||
if not isinstance(client, Redis):
|
if not isinstance(client, Redis):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
@ -86,7 +89,7 @@ class RedisStore(ByteStore):
|
|||||||
self.client = _client
|
self.client = _client
|
||||||
|
|
||||||
if not isinstance(ttl, int) and ttl is not None:
|
if not isinstance(ttl, int) and ttl is not None:
|
||||||
raise TypeError(f"Expected int or None, got {type(ttl)} instead.")
|
raise TypeError(f"Expected int or None, got {type(ttl)=} instead.")
|
||||||
|
|
||||||
self.ttl = ttl
|
self.ttl = ttl
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user