-
Notifications
You must be signed in to change notification settings - Fork 985
Pub Sub (4.0)
lettuce provides support for publish/subscribe connections. The connection is notified on message/subscribed/unsubscribed events after subscribing to channels or patterns. Sync, async and reactive API's are available to operate on the connection.
A connection can notify multiple listeners that implement RedisPubSubListener
(lettuce provides a RedisPubSubAdapter
for convenience). It does not matter over which API (sync, async or reactive) the listener registers. All listener registrations are kept within the StatefulRedisPubSubConnection
.
StatefulRedisPubSubConnection<String, String> connection = client.connectPubSub()
connection.addListener(new RedisPubSubListener<String, String>() { ... })
RedisPubSubCommands<String, String> sync = connection.sync();
sync.subscribe("channel");
StatefulRedisPubSubConnection<String, String> connection = client.connectPubSub()
connection.addListener(new RedisPubSubListener<String, String>() { ... })
RedisPubSubAsyncCommands<String, String> async = connection.async();
RedisFuture<Void> future = async.subscribe("channel");
The reactive API provides two hot Observable
s to listen on ChannelMessage
s and PatternMessage
s. The Observable
s receive all inbound messages. You can do filtering using the observable chain if you need to filter out the interesting ones, The Observable
stops triggering events when the subscriber unsubscribes from it.
StatefulRedisPubSubConnection<String, String> connection = client.connectPubSub()
RedisPubSubReactiveCommands<String, String> reactive = connection.reactive();
reactive.subscribe("channel").subscribe();
reactive.observePatterns().doOnNext(patternMessage -> {...}).subscribe()
Lettuce documentation was moved to https://redis.github.io/lettuce/overview/
Intro
Getting started
- Getting started
- Redis URI and connection details
- Basic usage
- Asynchronous API
- Reactive API
- Publish/Subscribe
- Transactions/Multi
- Scripting and Functions
- Redis Command Interfaces
- FAQ
HA and Sharding
Advanced usage
- Configuring Client resources
- Client Options
- Dynamic Command Interfaces
- SSL Connections
- Native Transports
- Unix Domain Sockets
- Streaming API
- Events
- Command Latency Metrics
- Tracing
- Stateful Connections
- Pipelining/Flushing
- Connection Pooling
- Graal Native Image
- Custom commands
Integration and Extension
Internals