chore(feat): support namespace in Pub/Sub commands
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.
@dakshmehta007 Thank you for your contribution. Please use .x.py format before committing-and-pushing the changes to make linters happy.
@dakshmehta007 Lot of thanks for your contribution, it's a great feature!
@dakshmehta007 Please, check a test and try to fix them
@dakshmehta007 Thank you for your contribution. Please use
.x.py formatbefore 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.
@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?