Skip to content

Commit

Permalink
Add support for ping command in Pub/Sub connection #1601
Browse files Browse the repository at this point in the history
Original pull request: #1641.
  • Loading branch information
dengliming authored and mp911de committed Mar 4, 2021
1 parent bc9b771 commit 3979a93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/java/io/lettuce/core/pubsub/PubSubEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

/**
* @author Mark Paluch
* @author dengliming
*/
public class PubSubEndpoint<K, V> extends DefaultEndpoint {

Expand All @@ -50,13 +51,14 @@ public class PubSubEndpoint<K, V> extends DefaultEndpoint {

static {

ALLOWED_COMMANDS_SUBSCRIBED = new HashSet<>(5, 1);
ALLOWED_COMMANDS_SUBSCRIBED = new HashSet<>(6, 1);

ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.SUBSCRIBE.name());
ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.PSUBSCRIBE.name());
ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.UNSUBSCRIBE.name());
ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.PUNSUBSCRIBE.name());
ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.QUIT.name());
ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.PING.name());

SUBSCRIBE_COMMANDS = new HashSet<>(2, 1);

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/io/lettuce/core/pubsub/PubSubCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* @author Will Glozer
* @author Mark Paluch
* @author Tugdual Grall
* @author dengliming
*/
class PubSubCommandTest extends AbstractRedisClientTest implements RedisPubSubListener<String, String> {

Expand Down Expand Up @@ -492,13 +493,13 @@ void pingNotAllowedInSubscriptionState() {

TestFutures.awaitOrTimeout(pubsub.subscribe(channel));

assertThatThrownBy(() -> TestFutures.getOrTimeout(pubsub.ping())).isInstanceOf(RedisException.class)
assertThatThrownBy(() -> TestFutures.getOrTimeout(pubsub.echo("ping"))).isInstanceOf(RedisException.class)
.hasMessageContaining("not allowed");
pubsub.unsubscribe(channel);

Wait.untilTrue(() -> channels.size() == 2).waitOrTimeout();

assertThat(TestFutures.getOrTimeout(pubsub.ping())).isEqualTo("PONG");
assertThat(TestFutures.getOrTimeout(pubsub.echo("ping"))).isEqualTo("ping");
}

// RedisPubSubListener implementation
Expand Down

0 comments on commit 3979a93

Please sign in to comment.