Skip to content

Add support for PubSub subscriptions with binary channel names and handlers#4068

Merged
petyaslavova merged 7 commits into
masterfrom
ps_support_binary_channel_names_with_handlers
May 21, 2026
Merged

Add support for PubSub subscriptions with binary channel names and handlers#4068
petyaslavova merged 7 commits into
masterfrom
ps_support_binary_channel_names_with_handlers

Conversation

@petyaslavova

@petyaslavova petyaslavova commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds a public Subscription(name, handler=None) value type for PubSub subscriptions and accepts it positionally in subscribe, psubscribe, and ssubscribe across sync, async, and cluster PubSub paths.

The new input form removes the kwargs-only limitation for handler-backed subscriptions.
Since Python keyword argument keys must be text strings, users previously could not attach handlers to arbitrary binary channel, pattern, or shard channel names.
Subscription keeps the existing APIs intact while adding a binary-safe way to bind handlers.

Reconnect replay now preserves handler-backed binary subscriptions by replaying them as positional Subscription objects instead of decoding names into kwargs.
Cluster sharded PubSub forwarding and shard migration paths were updated similarly, so handler associations survive reconnects and slot movement without requiring text-decodable channel names.

Docs now show the new Subscription form, mixed positional usage, and compatibility with the existing kwargs handler style.
Type hints were updated for the affected subscribe methods, and Subscription is re-exported from both redis and redis.asyncio.

Tests cover sync and async binary channel, pattern, and shard channel handlers, reconnect replay with handlers, and cluster shard routing/migration behavior.


Note

Medium Risk
Touches PubSub subscribe/resubscribe and cluster shard routing paths across sync+async clients; behavior changes around handler attachment and reconnect replay could affect subscription state in edge cases, though changes are well-covered by new tests.

Overview
Adds a public Subscription(name, handler=None) value type and extends subscribe/psubscribe/ssubscribe (sync, asyncio, cluster, and multidb) to accept handler-backed subscriptions positionally, enabling callbacks for binary channel/pattern/shard names that can’t be expressed as kwargs.

Refactors PubSub argument parsing and reconnect replay to use new helper utilities (parse_pubsub_subscriptions, pubsub_subscription_args) so handler-backed subscriptions are re-applied without decoding names into keyword keys; updates cluster shard subscription forwarding/migration to pass Subscription objects instead of decoded kwargs.

Re-exports Subscription from redis and redis.asyncio, updates docs with mixed-form examples, and adds sync/async tests covering binary handler subscriptions, reconnect resubscribe, and cluster shard migration behavior.

Reviewed by Cursor Bugbot for commit 8e129d2. Bugbot is set up for automated code reviews on this repo. Configure here.

@petyaslavova petyaslavova added the feature New feature label May 15, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 570af56. Configure here.

Comment thread redis/commands/helpers.py
@jit-ci

jit-ci Bot commented May 15, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@petyaslavova petyaslavova requested a review from vladvildanov May 20, 2026 11:27
@petyaslavova petyaslavova merged commit ea76084 into master May 21, 2026
343 checks passed
@petyaslavova petyaslavova deleted the ps_support_binary_channel_names_with_handlers branch May 21, 2026 12:23
petyaslavova added a commit that referenced this pull request May 26, 2026
…ndlers (#4068)

* Add support for PubSub subscriptions with binary channel names and handlers

* Applying review comment + fixing spelling and linters errors

* Fixing linters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants