kvrocks icon indicating copy to clipboard operation
kvrocks copied to clipboard

chore(feat): support namespace in Pub/Sub commands

Open dakshmehta007 opened this issue 11 months ago • 5 comments

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 avatar Mar 11 '25 19:03 dakshmehta007

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

torwig avatar Mar 11 '25 19:03 torwig

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

aleksraiden avatar Mar 11 '25 20:03 aleksraiden

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

aleksraiden avatar Mar 12 '25 11:03 aleksraiden

@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.

SharonIV0x86 avatar Mar 13 '25 05:03 SharonIV0x86

@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?

torwig avatar Mar 13 '25 05:03 torwig