Interface RedisPubSubCommands
- All Known Subinterfaces:
DefaultedRedisClusterConnection
,DefaultedRedisConnection
,RedisClusterConnection
,RedisCommands
,RedisConnection
,RedisConnectionUtils.RedisConnectionProxy
,StringRedisConnection
- All Known Implementing Classes:
AbstractRedisConnection
,DefaultStringRedisConnection
,JedisClusterConnection
,JedisConnection
,LettuceClusterConnection
,LettuceConnection
public interface RedisPubSubCommands
PubSub-specific Redis commands.
- Author:
- Costin Leau, Mark Paluch, Christoph Strobl
-
Method Summary
Modifier and TypeMethodDescriptionReturns the current subscription for this connection or null if the connection is not subscribed.boolean
Indicates whether the current connection is subscribed (to at least one channel) or not.void
pSubscribe
(MessageListener listener, byte[]... patterns) Subscribes the connection to all channels matching the given patterns.publish
(byte[] channel, byte[] message) Publishes the given message to the given channel.void
subscribe
(MessageListener listener, byte[]... channels) Subscribes the connection to the given channels.
-
Method Details
-
isSubscribed
boolean isSubscribed()Indicates whether the current connection is subscribed (to at least one channel) or not.- Returns:
- true if the connection is subscribed, false otherwise
-
getSubscription
Returns the current subscription for this connection or null if the connection is not subscribed.- Returns:
- the current subscription, null if none is available.
-
publish
Publishes the given message to the given channel.- Parameters:
channel
- the channel to publish to. Must not be null.message
- message to publish. Must not be null.- Returns:
- the number of clients that received the message or null when used in pipeline / transaction.
- See Also:
-
subscribe
Subscribes the connection to the given channels. Once subscribed, a connection enters listening mode and can only subscribe to other channels or unsubscribe. No other commands are accepted until the connection is unsubscribed.Note that this operation is blocking and the current thread starts waiting for new messages immediately.
- Parameters:
listener
- message listener, must not be null.channels
- channel names, must not be null.- See Also:
-
pSubscribe
Subscribes the connection to all channels matching the given patterns. Once subscribed, a connection enters listening mode and can only subscribe to other channels or unsubscribe. No other commands are accepted until the connection is unsubscribed.Note that this operation is blocking and the current thread starts waiting for new messages immediately.
- Parameters:
listener
- message listener, must not be null.patterns
- channel name patterns, must not be null.- See Also:
-