-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Support Redis Cluster #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Redis Cluster by detecting cluster mode, adding key hash tagging for key grouping, and ensuring that Redis pipelines run with transaction disabled in cluster mode.
- Detect cluster mode on client initialization
- Integrate key hashing via get_key_with_hash_tag
- Adjust pipeline creation to use transaction=not cluster_mode for TTL and search operations
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/test_cluster_mode.py | Introduces tests for sync cluster detection, key hash tagging, and pipeline transaction setting |
tests/test_async_cluster_mode.py | Introduces tests for async cluster detection and key hash tagging with appropriate pipeline behavior |
langgraph/store/redis/base.py | Adds get_key_with_hash_tag function and detects cluster mode in init with corresponding pipeline adjustments |
langgraph/store/redis/aio.py | Updates async pipeline creation to use cluster mode flag in TTL and search operations |
langgraph/store/redis/init.py | Adapts synchronous store operations to handle key hash tagging and pipeline configuration for cluster mode |
Comments suppressed due to low confidence (1)
langgraph/store/redis/aio.py:213
- [nitpick] In the vector search branch, the pipeline is created with a fixed transaction=False. For consistency with other usage (i.e. transaction=not self.cluster_mode), consider aligning this parameter to improve maintainability.
pipeline = self._redis.pipeline(transaction=False)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Redis Cluster and Redis Enterprise by detecting cluster mode and conditionally applying single-key commands (e.g., direct expire calls) instead of multi-key or transactional pipelines. Key changes include:
- Conditional TTL application and pipeline usage in both the synchronous and asynchronous stores.
- Updates to cluster mode detection and configuration across various modules.
- New tests and configuration adjustments to simulate and verify the different client behaviors.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
tests/test_async_cluster_mode.py | Added tests to verify different behaviors for cluster vs. non-cluster clients. |
tests/conftest.py | Modified the Redis-clearing fixture with a small delay and additional logging. |
pyproject.toml | Removed dependency on types-redis as part of the upgrade. |
langgraph/store/redis/base.py | Introduced a cluster_mode attribute and updated TTL handling for cluster mode. |
langgraph/store/redis/aio.py | Adjusted async logic to detect cluster mode and conditionally use pipelines. |
langgraph/store/redis/init.py | Added cluster detection in the synchronous RedisStore. |
langgraph/checkpoint/redis/* | Updated client connection closing and error handling for improved clarity. |
@@ -335,16 +389,21 @@ def _batch_put_ops( | |||
"updated_at": datetime.now(timezone.utc).timestamp(), | |||
} | |||
) | |||
vector_key = f"{STORE_VECTOR_PREFIX}{REDIS_KEY_SEPARATOR}{doc_id}" | |||
vector_keys.append(vector_key) | |||
redis_vector_key = f"{STORE_VECTOR_PREFIX}{REDIS_KEY_SEPARATOR}{doc_id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector_key
was defined just above here as vector_key: tuple[str, str] = (ns, key)
and used for something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @abrookins !
@abrookins I rebased against main locally, all tests passed. But I get errors with mypy for linting and type checking:
|
Co-authored-by: Copilot <[email protected]>
dec7d99
to
e5ccb9e
Compare
Add support for Redis Cluster in the Store implementations:
This is "part one" because our lower-level dependency, RedisVL, also needs to update to support cluster-aware clients. However, with the changes in this PR, users who use Redis clusters through a proxy (with a non-cluster-aware client, e.g.
Redis
notRedisCluster
) can setcluster_mode=True
so we change our multi-key command behavior.