Skip to content

feat: add Redis Cluster support - #2886

Closed
fbartonoctopus wants to merge 9 commits into
ag2ai:mainfrom
fbartonoctopus:feat/redis-cluster-support
Closed

fbartonoctopus wants to merge 9 commits into
ag2ai:mainfrom
fbartonoctopus:feat/redis-cluster-support

Conversation

@fbartonoctopus

Copy link
Copy Markdown

Summary

Add RedisClusterBroker for Redis Cluster deployments, resolving #1170.

Uses redis.asyncio.cluster.RedisCluster under the hood so commands are
automatically routed to the correct cluster node — no more MOVED errors.

What's included

  • RedisClusterBroker — drop-in replacement for RedisBroker with cluster-compatible parameters
  • ClusterConnectionState — connection lifecycle using RedisCluster directly (not ConnectionPool)
  • TestRedisClusterBroker — mock-connection testing utility
  • RedisClusterRouter — FastAPI integration with full @overload subscriber signatures
  • driver_info migration — existing ConnectionState migrated from deprecated lib_name/lib_version to DriverInfo API
  • Docker Compose — single-node Redis Cluster service on port 7000
  • Tests — 13 unit tests + 6 integration tests (streams, lists, consumer groups)
  • Documentation — cluster usage guide with examples, nav entry

Subscription type support

Type Min redis-py
Streams >= 5.0.0
Lists >= 5.0.0
Channels (PubSub) >= 8.0.0 (async cluster pubsub, currently beta)

redis-py 8.x compatibility

Analysed the breaking changes in redis-py 8.0.0b1/b2. Default legacy_responses=True
preserves RESP2-compatible response shapes — no impact on faststream's stream/list/channel
parsing. The redis dependency upper bound is bumped from <8.0.0 to <9.0.0.

Closes

Closes #1170


Warp conversation · Implementation plan

Co-Authored-By: Oz oz-agent@warp.dev

fbartonoctopus and others added 9 commits May 22, 2026 11:06
Allow redis-py 8.x which adds async RedisCluster pubsub support
(PR redis/redis-py#3736, released in 8.0.0b1).

Co-Authored-By: Oz <oz-agent@warp.dev>
Replace deprecated lib_name/lib_version kwargs with the new
driver_info=DriverInfo().add_upstream_driver('faststream', __version__)
API. This fixes DeprecationWarnings emitted by redis-py >= 7.4.0.

The CLIENT SETINFO LIB-NAME is now reported as
'redis-py(faststream_v{version})'.

Co-Authored-By: Oz <oz-agent@warp.dev>
Add ClusterConnectionState that creates a RedisCluster[bytes] client
directly (RedisCluster manages its own per-node connection pools).

Unsupported ConnectionPool params (db, socket_read_size, socket_type,
retry_on_timeout, parser_class, encoder_class, decode_responses) are
automatically filtered out.

Driver identification uses driver_info on redis-py 8.x and falls back
to lib_name/lib_version on 7.x for compatibility.

Co-Authored-By: Oz <oz-agent@warp.dev>
Add RedisClusterBroker that connects via redis.asyncio.cluster.RedisCluster
instead of redis.asyncio.client.Redis. Supports all subscription types
(channels, streams, lists) with the same API as RedisBroker.

The broker:
- Accepts only cluster-compatible connection parameters
- Filters out unsupported options (db, socket_read_size, etc.)
- Uses ClusterConnectionState for connection management
- Inherits publish/subscribe/request from RedisBroker unchanged

Channel (PubSub) subscribers require redis-py >= 8.0.0.
Streams and lists work with redis-py >= 5.0.0.

Co-Authored-By: Oz <oz-agent@warp.dev>
Add TestRedisClusterBroker for testing RedisClusterBroker without
a real Redis Cluster connection. Follows the same mock-connection
pattern as TestRedisBroker.

Co-Authored-By: Oz <oz-agent@warp.dev>
Add RedisClusterRouter that wraps RedisClusterBroker for use as a
FastAPI StreamRouter. Mirrors RedisRouter's subscriber/publisher API
with cluster-compatible connection parameters.

Co-Authored-By: Oz <oz-agent@warp.dev>
Tests cover:
- ClusterConnectionState: parameter filtering, max_connections default,
  initial state, client access guard
- RedisClusterBroker: instantiation, connection state type, URL db
  filtering, subscriber/publisher registration
- TestRedisClusterBroker: mock publish/subscribe on lists, streams,
  and channels

Co-Authored-By: Oz <oz-agent@warp.dev>
Add a single-node Redis Cluster service to docker-compose.yaml on
port 7000, with justfile commands for redis-cluster-up/stop/logs.

Integration tests (marked @pytest.mark.connected) cover:
- Cluster connection and ping
- Stream publish/consume
- List publish/consume
- Stream consumer groups

Co-Authored-By: Oz <oz-agent@warp.dev>
Add docs/docs/en/redis/cluster/index.md covering:
- Basic usage with RedisClusterBroker
- Supported subscription types and redis-py version requirements
- Connection parameters reference
- FastAPI integration with RedisClusterRouter
- Testing with TestRedisClusterBroker
- Docker Compose example for local development

Update the Redis index page with a link to the cluster docs.

Co-Authored-By: Oz <oz-agent@warp.dev>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file Redis Issues related to `faststream.redis` module and Redis features labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation Redis Issues related to `faststream.redis` module and Redis features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Adds support for the Redis cluster

2 participants