Skip to content

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

Open
petyaslavova wants to merge 3 commits into
masterfrom
ps_support_binary_channel_names_with_handlers
Open

Add support for PubSub subscriptions with binary channel names and handlers#4068
petyaslavova wants to merge 3 commits into
masterfrom
ps_support_binary_channel_names_with_handlers

Conversation

@petyaslavova
Copy link
Copy Markdown
Collaborator

@petyaslavova petyaslavova commented May 15, 2026

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 core PubSub subscribe/resubscribe paths (sync, asyncio, and cluster sharded pubsub), so regressions could break reconnect behavior or handler dispatching, especially around mixed positional/keyword subscriptions.

Overview
Adds a new public Subscription(name, handler=None) value type and re-exports it from redis and redis.asyncio, enabling handler-backed PubSub subscriptions for channel/pattern names that can’t be expressed as Python kwargs (including arbitrary bytes).

Updates subscribe/psubscribe/ssubscribe across sync, asyncio, cluster, and multidb clients to accept positional Subscription objects (and mix them with existing kwargs), centralizing argument parsing in new helper functions and changing reconnect resubscription to replay handler-backed entries as Subscription objects (avoiding decoding into kwarg keys). Docs and tests are expanded to cover binary names with handlers, reconnect replay, and cluster shard-channel routing/migration with handlers preserved.

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

@petyaslavova petyaslavova added the feature New feature label May 15, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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
Copy link
Copy Markdown

jit-ci Bot commented May 15, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

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.

1 participant