Interface PubSubBaseCommands
-
- All Known Implementing Classes:
BaseClient,GlideClient,GlideClusterClient
public interface PubSubBaseCommandsSupports commands for the "Pub/Sub" group for standalone and cluster clients.- See Also:
- Pub/Sub Commands
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.Set<java.lang.String>ALL_CHANNELSConstant representing "unsubscribe from all channels".static java.util.Set<java.lang.String>ALL_PATTERNSConstant representing "unsubscribe from all patterns".
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Void>psubscribe(java.util.Set<java.lang.String> patterns, int timeoutMs)Subscribes the client to channels matching the specified patterns with a timeout.java.util.concurrent.CompletableFuture<java.lang.Void>psubscribeLazy(java.util.Set<java.lang.String> patterns)Subscribes the client to channels matching the specified patterns.java.util.concurrent.CompletableFuture<java.lang.String>publish(GlideString message, GlideString channel)Publishes message on pubsub channel.java.util.concurrent.CompletableFuture<java.lang.String>publish(java.lang.String message, java.lang.String channel)Publishes message on pubsub channel.java.util.concurrent.CompletableFuture<java.lang.String[]>pubsubChannels()Lists the currently active channels.java.util.concurrent.CompletableFuture<GlideString[]>pubsubChannels(GlideString pattern)Lists the currently active channels.java.util.concurrent.CompletableFuture<java.lang.String[]>pubsubChannels(java.lang.String pattern)Lists the currently active channels.java.util.concurrent.CompletableFuture<GlideString[]>pubsubChannelsBinary()Lists the currently active channels.
Unlike ofpubsubChannels(), returns channel names asGlideStrings.java.util.concurrent.CompletableFuture<java.lang.Long>pubsubNumPat()Returns the number of unique patterns that are subscribed to by clients.java.util.concurrent.CompletableFuture<java.util.Map<GlideString,java.lang.Long>>pubsubNumSub(GlideString[] channels)Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,java.lang.Long>>pubsubNumSub(java.lang.String[] channels)Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.java.util.concurrent.CompletableFuture<java.lang.Void>punsubscribe(int timeoutMs)Unsubscribes the client from all currently subscribed patterns with a timeout.java.util.concurrent.CompletableFuture<java.lang.Void>punsubscribe(java.util.Set<java.lang.String> patterns, int timeoutMs)Unsubscribes the client from the specified patterns with a timeout.java.util.concurrent.CompletableFuture<java.lang.Void>punsubscribeLazy()Unsubscribes the client from all currently subscribed patterns.java.util.concurrent.CompletableFuture<java.lang.Void>punsubscribeLazy(java.util.Set<java.lang.String> patterns)Unsubscribes the client from the specified patterns.java.util.concurrent.CompletableFuture<java.lang.Void>subscribe(java.util.Set<java.lang.String> channels, int timeoutMs)Subscribes the client to the specified channels with a timeout.java.util.concurrent.CompletableFuture<java.lang.Void>subscribeLazy(java.util.Set<java.lang.String> channels)Subscribes the client to the specified channels.java.util.concurrent.CompletableFuture<java.lang.Void>unsubscribe(int timeoutMs)Unsubscribes the client from all currently subscribed channels with a timeout.java.util.concurrent.CompletableFuture<java.lang.Void>unsubscribe(java.util.Set<java.lang.String> channels, int timeoutMs)Unsubscribes the client from the specified channels with a timeout.java.util.concurrent.CompletableFuture<java.lang.Void>unsubscribeLazy()Unsubscribes the client from all currently subscribed channels.java.util.concurrent.CompletableFuture<java.lang.Void>unsubscribeLazy(java.util.Set<java.lang.String> channels)Unsubscribes the client from the specified channels.
-
-
-
Field Detail
-
ALL_CHANNELS
static final java.util.Set<java.lang.String> ALL_CHANNELS
Constant representing "unsubscribe from all channels". Pass this tounsubscribeLazy(Set)orunsubscribe(Set, int)to unsubscribe from all channels.- Example:
// Unsubscribe from all channels client.unsubscribeLazy(PubSubBaseCommands.ALL_CHANNELS).get();
-
ALL_PATTERNS
static final java.util.Set<java.lang.String> ALL_PATTERNS
Constant representing "unsubscribe from all patterns". Pass this topunsubscribeLazy(Set)orpunsubscribe(Set, int)to unsubscribe from all patterns.- Example:
// Unsubscribe from all patterns client.punsubscribeLazy(PubSubBaseCommands.ALL_PATTERNS).get();
-
-
Method Detail
-
publish
java.util.concurrent.CompletableFuture<java.lang.String> publish(java.lang.String message, java.lang.String channel)Publishes message on pubsub channel.- Parameters:
message- The message to publish.channel- The channel to publish the message on.- Returns:
OK.- See Also:
- valkey.io for details.
- Example:
String response = client.publish("The cat said 'meow'!", "announcements").get(); assert response.equals("OK");
-
publish
java.util.concurrent.CompletableFuture<java.lang.String> publish(GlideString message, GlideString channel)
Publishes message on pubsub channel.- Parameters:
message- The message to publish.channel- The channel to publish the message on.- Returns:
OK.- See Also:
- valkey.io for details.
- Example:
String response = client.publish(gs("The cat said 'meow'!"), gs("announcements")).get(); assert response.equals("OK");
-
pubsubChannels
java.util.concurrent.CompletableFuture<java.lang.String[]> pubsubChannels()
Lists the currently active channels.- Returns:
- An
Arrayof all active channels. - See Also:
- valkey.io for details.
- Example:
String[] response = client.pubsubChannels().get(); assert Arrays.equals(new String[] { "channel1", "channel2" });
-
pubsubChannelsBinary
java.util.concurrent.CompletableFuture<GlideString[]> pubsubChannelsBinary()
Lists the currently active channels.
Unlike ofpubsubChannels(), returns channel names asGlideStrings.- Returns:
- An
Arrayof all active channels. - See Also:
- valkey.io for details.
- Example:
GlideString[] response = client.pubsubChannels().get(); assert Arrays.equals(new GlideString[] { "channel1", "channel2" });
-
pubsubChannels
java.util.concurrent.CompletableFuture<java.lang.String[]> pubsubChannels(java.lang.String pattern)
Lists the currently active channels.- Parameters:
pattern- A glob-style pattern to match active channels.- Returns:
- An
Arrayof currently active channels matching the given pattern. - See Also:
- valkey.io for details.
- Example:
String[] response = client.pubsubChannels("news.*").get(); assert Arrays.equals(new String[] { "news.sports", "news.weather" });
-
pubsubChannels
java.util.concurrent.CompletableFuture<GlideString[]> pubsubChannels(GlideString pattern)
Lists the currently active channels.- Parameters:
pattern- A glob-style pattern to match active channels.- Returns:
- An
Arrayof currently active channels matching the given pattern. - See Also:
- valkey.io for details.
- Example:
GlideString[] response = client.pubsubChannels(gs("news.*")).get(); assert Arrays.equals(new GlideString[] { gs("news.sports"), gs("news.weather") });
-
pubsubNumPat
java.util.concurrent.CompletableFuture<java.lang.Long> pubsubNumPat()
Returns the number of unique patterns that are subscribed to by clients.- Returns:
- The number of unique patterns.
- See Also:
- valkey.io for details.
- Example:
Long result = client.pubsubNumPat().get(); assert result == 3L;
-
pubsubNumSub
java.util.concurrent.CompletableFuture<java.util.Map<java.lang.String,java.lang.Long>> pubsubNumSub(java.lang.String[] channels)
Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.- Parameters:
channels- The list of channels to query for the number of subscribers.- Returns:
- A
Mapwhere keys are the channel names and values are the numbers of subscribers. - See Also:
- valkey.io for details.
- Example:
Map<String, Long> result = client.pubsubNumSub(new String[] {"channel1", "channel2"}).get(); assert result.equals(Map.of("channel1", 3L, "channel2", 5L));
-
pubsubNumSub
java.util.concurrent.CompletableFuture<java.util.Map<GlideString,java.lang.Long>> pubsubNumSub(GlideString[] channels)
Returns the number of subscribers (exclusive of clients subscribed to patterns) for the specified channels.- Parameters:
channels- The list of channels to query for the number of subscribers.- Returns:
- A
Mapwhere keys are the channel names and values are the numbers of subscribers. - See Also:
- valkey.io for details.
- Example:
Map<GlideString, Long> result = client.pubsubNumSub(new GlideString[] {gs("channel1"), gs("channel2")}).get(); assert result.equals(Map.of(gs("channel1"), 3L, gs("channel2"), 5L));
-
subscribeLazy
java.util.concurrent.CompletableFuture<java.lang.Void> subscribeLazy(java.util.Set<java.lang.String> channels)
Subscribes the client to the specified channels.This command updates the client's internal desired subscription state without waiting for server confirmation. It returns immediately after updating the local state. The client will attempt to subscribe asynchronously in the background.
Note: Use
getSubscriptions()to verify the actual server-side subscription state.- Parameters:
channels- A set of channel names to subscribe to- Returns:
- A
CompletableFuturethat completes when the subscription request is processed - See Also:
- valkey.io for details
- Example:
client.subscribeLazy(Set.of("news", "updates")).get();
-
subscribe
java.util.concurrent.CompletableFuture<java.lang.Void> subscribe(java.util.Set<java.lang.String> channels, int timeoutMs)Subscribes the client to the specified channels with a timeout.This command updates the client's internal desired subscription state and waits for server confirmation.
- Parameters:
channels- A set of channel names to subscribe totimeoutMs- Maximum time in milliseconds to wait for subscription confirmation. A value of 0 blocks indefinitely until confirmation.- Returns:
- A
CompletableFuturethat completes when the subscription is confirmed or times out - See Also:
- valkey.io for details
- Example:
client.subscribe(Set.of("news", "updates"), 5000).get();
-
psubscribeLazy
java.util.concurrent.CompletableFuture<java.lang.Void> psubscribeLazy(java.util.Set<java.lang.String> patterns)
Subscribes the client to channels matching the specified patterns.This command updates the client's internal desired subscription state without waiting for server confirmation. It returns immediately after updating the local state. The client will attempt to subscribe asynchronously in the background.
Patterns use glob-style matching:
*matches any sequence of characters?matches any single character[abc]matches one character from the set
Note: Use
getSubscriptions()to verify the actual server-side subscription state.- Parameters:
patterns- A set of glob patterns to subscribe to- Returns:
- A
CompletableFuturethat completes when the subscription request is processed - See Also:
- valkey.io for details
- Example:
client.psubscribeLazy(Set.of("news.*", "updates.*")).get();
-
psubscribe
java.util.concurrent.CompletableFuture<java.lang.Void> psubscribe(java.util.Set<java.lang.String> patterns, int timeoutMs)Subscribes the client to channels matching the specified patterns with a timeout.This command updates the client's internal desired subscription state and waits for server confirmation.
- Parameters:
patterns- A set of glob patterns to subscribe totimeoutMs- Maximum time in milliseconds to wait for subscription confirmation. A value of 0 blocks indefinitely until confirmation.- Returns:
- A
CompletableFuturethat completes when the subscription is confirmed or times out - See Also:
- valkey.io for details
- Example:
client.psubscribe(Set.of("news.*", "updates.*"), 5000).get();
-
unsubscribeLazy
java.util.concurrent.CompletableFuture<java.lang.Void> unsubscribeLazy()
Unsubscribes the client from all currently subscribed channels.This command updates the client's internal desired subscription state without waiting for server confirmation. It returns immediately after updating the local state. The client will attempt to unsubscribe asynchronously in the background.
Note: Use
getSubscriptions()to verify the actual server-side subscription state.- Returns:
- A
CompletableFuturethat completes when the unsubscription request is processed - See Also:
- valkey.io for details
- Example:
client.unsubscribeLazy().get();
-
unsubscribeLazy
java.util.concurrent.CompletableFuture<java.lang.Void> unsubscribeLazy(java.util.Set<java.lang.String> channels)
Unsubscribes the client from the specified channels.This command updates the client's internal desired subscription state without waiting for server confirmation. It returns immediately after updating the local state. The client will attempt to unsubscribe asynchronously in the background.
Note: Use
getSubscriptions()to verify the actual server-side subscription state.- Parameters:
channels- A set of channel names to unsubscribe from- Returns:
- A
CompletableFuturethat completes when the unsubscription request is processed - See Also:
- valkey.io for details
- Example:
client.unsubscribeLazy(Set.of("news", "updates")).get();
-
unsubscribe
java.util.concurrent.CompletableFuture<java.lang.Void> unsubscribe(java.util.Set<java.lang.String> channels, int timeoutMs)Unsubscribes the client from the specified channels with a timeout.This command updates the client's internal desired subscription state and waits for server confirmation.
- Parameters:
channels- A set of channel names to unsubscribe fromtimeoutMs- Maximum time in milliseconds to wait for unsubscription confirmation. A value of 0 blocks indefinitely until confirmation.- Returns:
- A
CompletableFuturethat completes when the unsubscription is confirmed or times out - See Also:
- valkey.io for details
- Example:
client.unsubscribe(Set.of("news", "updates"), 5000).get();
-
unsubscribe
java.util.concurrent.CompletableFuture<java.lang.Void> unsubscribe(int timeoutMs)
Unsubscribes the client from all currently subscribed channels with a timeout.- Parameters:
timeoutMs- Maximum time in milliseconds to wait for unsubscription confirmation- Returns:
- A
CompletableFuturethat completes when the unsubscription is confirmed or times out - See Also:
- valkey.io for details
- Example:
client.unsubscribe(5000).get();
-
punsubscribeLazy
java.util.concurrent.CompletableFuture<java.lang.Void> punsubscribeLazy()
Unsubscribes the client from all currently subscribed patterns.This command updates the client's internal desired subscription state without waiting for server confirmation. It returns immediately after updating the local state. The client will attempt to unsubscribe asynchronously in the background.
Note: Use
getSubscriptions()to verify the actual server-side subscription state.- Returns:
- A
CompletableFuturethat completes when the unsubscription request is processed - See Also:
- valkey.io for details
- Example:
client.punsubscribeLazy().get();
-
punsubscribeLazy
java.util.concurrent.CompletableFuture<java.lang.Void> punsubscribeLazy(java.util.Set<java.lang.String> patterns)
Unsubscribes the client from the specified patterns.This command updates the client's internal desired subscription state without waiting for server confirmation. It returns immediately after updating the local state. The client will attempt to unsubscribe asynchronously in the background.
Note: Use
getSubscriptions()to verify the actual server-side subscription state.- Parameters:
patterns- A set of glob patterns to unsubscribe from- Returns:
- A
CompletableFuturethat completes when the unsubscription request is processed - See Also:
- valkey.io for details
- Example:
client.punsubscribeLazy(Set.of("news.*", "updates.*")).get();
-
punsubscribe
java.util.concurrent.CompletableFuture<java.lang.Void> punsubscribe(java.util.Set<java.lang.String> patterns, int timeoutMs)Unsubscribes the client from the specified patterns with a timeout.This command updates the client's internal desired subscription state and waits for server confirmation.
- Parameters:
patterns- A set of glob patterns to unsubscribe fromtimeoutMs- Maximum time in milliseconds to wait for unsubscription confirmation. A value of 0 blocks indefinitely until confirmation.- Returns:
- A
CompletableFuturethat completes when the unsubscription is confirmed or times out - See Also:
- valkey.io for details
- Example:
client.punsubscribe(Set.of("news.*", "updates.*"), 5000).get();
-
punsubscribe
java.util.concurrent.CompletableFuture<java.lang.Void> punsubscribe(int timeoutMs)
Unsubscribes the client from all currently subscribed patterns with a timeout.- Parameters:
timeoutMs- Maximum time in milliseconds to wait for unsubscription confirmation- Returns:
- A
CompletableFuturethat completes when the unsubscription is confirmed or times out - See Also:
- valkey.io for details
- Example:
client.punsubscribe(5000).get();
-
-