-
Notifications
You must be signed in to change notification settings - Fork 148
Description
Describe the feature
Add comprehensive PubSub (Publish/Subscribe) command support to the Jedis compatibility layer, including:
Publishing commands:
publish() - Publish messages to channels (String and binary variants)
pubsubChannels() - List active channels with optional pattern filtering
pubsubNumPat() - Get count of pattern subscriptions
pubsubNumSub() - Get subscriber counts for specific channels
Subscription commands:
subscribe() / unsubscribe() - Exact channel subscriptions
psubscribe() / punsubscribe() - Pattern-based subscriptions
ssubscribe() / sunsubscribe() - Sharded channel subscriptions (cluster mode)
All commands include both String and binary (byte[]) variants, providing full Jedis API compatibility for PubSub operations.
Use Case
PubSub is a critical feature for real-time applications using Redis/Valkey. Applications migrating from Jedis to Valkey GLIDE need complete PubSub API compatibility to enable:
- Drop-in replacement: Existing Jedis applications using PubSub can migrate without code changes
- Channel management: Query active channels, subscriber counts, and pattern subscriptions
- Message publishing: Publish messages to channels and patterns
- Subscription management: Subscribe/unsubscribe from channels, patterns, and sharded channels
- Testing compatibility: Existing test suites that use PubSub commands work without modification
Without these commands, developers must:
- Rewrite all PubSub code to use GLIDE's native subscription API
- Lose ability to query PubSub state (channels, subscriber counts)
- Use workarounds with sendCommand() which breaks API compatibility
- Delay or abandon migration to GLIDE
Real-world use cases:
- Event broadcasting systems
- Real-time notifications and alerts
- Distributed messaging architectures
- Cache invalidation patterns
- Live data streaming applications
Proposed Solution
The implementation adds complete PubSub support to the Jedis compatibility layer through 16 new methods across 4 publishing commands (publish, pubsubChannels, pubsubNumPat, pubsubNumSub) and 6 subscription command families (subscribe/unsubscribe, psubscribe/punsubscribe, ssubscribe/sunsubscribe), each with String and binary variants. Publishing and introspection commands leverage GLIDE's native PubSub APIs directly for optimal performance, while subscription commands use customCommand() to send commands to the server. All methods follow the executeCommandWithGlide() pattern for consistent error handling and include comprehensive JavaDoc with version compatibility info and migration guidance. The implementation includes 22 unit tests for API contract validation and 14 integration tests (disabled by default) for actual command execution. Documentation updates to compatibility-layer-migration-guide.md provide usage examples and clearly explain that while subscription commands send requests to the server, full PubSub functionality with message callbacks requires GLIDE's native StandaloneSubscriptionConfiguration or ClusterSubscriptionConfiguration approach.
Other Information
Architecture decisions:
Publish commands:
- Use GLIDE's native APIs directly for optimal performance
- publish() returns 0 as GLIDE doesn't expose subscriber count
- Introspection commands (pubsubChannels, pubsubNumPat, pubsubNumSub) work seamlessly
Subscribe commands:
- Send subscription commands but don't handle messages
- Low-level implementation for API compatibility
- For full PubSub with message callbacks, use GLIDE's native configuration
StandaloneSubscriptionConfiguration subConfig =
StandaloneSubscriptionConfiguration.builder()
.subscription(PubSubChannelMode.EXACT, gs("channel"))
.subscription(PubSubChannelMode.PATTERN, gs("news.*"))
.callback((message, context) -> {
// Handle incoming messages
})
.build();
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
Client version used
valkey-glide-jedis-compatibility 2.+
Environment details (OS name and version, etc.)
macOS 14.7+ (aarch64), Ubuntu 20+, Amazon Linux 2/2023 JDK 11+ Valkey 7.2+, 8.0+, 8.1+ / Redis 6.2, 7.0, 7.1, 7.2