Skip to content

Conversation

dakshmehta007
Copy link

Support Namespace in Pub/Sub Commands (PR #2097 )

Opened by @PragmaTwice on February 10, 2024

Summary

This PR enhances Redis Pub/Sub commands by introducing namespace support. Previously, Pub/Sub mechanisms did not account for namespaces, which limited scalability in multi-tenant environments. This update ensures that channels respect namespace prefixes, providing proper tenant isolation and aligning Pub/Sub operations with Redis’s namespace-aware storage functionality.

Motivation

The lack of namespace compatibility in Pub/Sub commands makes multi-tenant implementations more complex. By enabling namespace support, this update allows better tenant segregation, improves security, and enhances integration with Redis’s existing namespace-based mechanisms.

Implementation Details

  • Updated subscription and unsubscription methods (SubscribeChannel, UnsubscribeChannel, PSubscribeChannel, PUnsubscribeChannel, SSubscribeChannel, and SUnsubscribeChannel) to prepend namespace keys to channel names using ComposeNamespaceKey.
  • Improved tracking mechanisms to manage both namespaced and non-namespaced subscriptions.
  • Modified subscription lists (subscribe_channels_, subscribe_patterns_, and subscribe_shard_channels_) to store namespaced versions of subscribed channels.
  • Integrated namespace handling with Redis storage to ensure proper support for slot encoding when required.

Next Steps

  • Verify compatibility of wildcard pattern subscriptions (PSUBSCRIBE) across different namespaces.
  • Add comprehensive test cases to validate namespace behavior in all Pub/Sub scenarios.

@torwig
Copy link
Contributor

torwig commented Mar 11, 2025

@dakshmehta007 Thank you for your contribution. Please use .x.py format before committing-and-pushing the changes to make linters happy.

@aleksraiden aleksraiden changed the title Support namespace in Pub/Sub commands chore(feat): support namespace in Pub/Sub commands Mar 11, 2025
@aleksraiden
Copy link
Contributor

@dakshmehta007 Lot of thanks for your contribution, it's a great feature!

@aleksraiden
Copy link
Contributor

@dakshmehta007 Please, check a test and try to fix them

@SharonIV0x86
Copy link
Contributor

@dakshmehta007 Thank you for your contribution. Please use .x.py format before committing-and-pushing the changes to make linters happy.

The linter seems happy but the cross platform builds don't. The Go's PubSub tests are failing on all platforms.

@torwig
Copy link
Contributor

torwig commented Mar 13, 2025

@dakshmehta007 Did you run tests on your local machine (./x.py test go if I'm not mistaken) or test the feature with local Kvrocks and redisc-cli?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants