From ce4e29ae425056b35c41a5024e0d58e51f68fb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaeyeon=20Kim=28=EA=B9=80=EC=9E=AC=EC=97=B0=29?= Date: Tue, 11 Jun 2024 23:08:05 +0900 Subject: [PATCH] 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. ![image](https://github.com/langchain-ai/langchain/assets/37469330/78c5d9ce-ee66-45b3-8dfe-ea29f125e6e9) ### 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 --- libs/community/langchain_community/storage/redis.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/community/langchain_community/storage/redis.py b/libs/community/langchain_community/storage/redis.py index 5e1b4fa56c..2bf205d7d7 100644 --- a/libs/community/langchain_community/storage/redis.py +++ b/libs/community/langchain_community/storage/redis.py @@ -18,7 +18,7 @@ class RedisStore(ByteStore): from langchain_community.utilities.redis import get_client client = get_client('redis://localhost:6379') - redis_store = RedisStore(client) + redis_store = RedisStore(client=client) # Set values for keys redis_store.mset([("key1", b"value1"), ("key2", b"value2")]) @@ -64,12 +64,15 @@ class RedisStore(ByteStore): "pip install redis" ) from e - if client and redis_url or client and client_kwargs: + if client and (redis_url or client_kwargs): raise ValueError( "Either a Redis client or a redis_url with optional client_kwargs " "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 not isinstance(client, Redis): raise TypeError( @@ -86,7 +89,7 @@ class RedisStore(ByteStore): self.client = _client 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.namespace = namespace