-
https://redis.github.io/lettuce/ha-sharding/#connection-count-for-a-redis-cluster-connection-object I sent subscribe command first and waited the result of subscribe future result. public class SubMain {
public static void main(String[] args) throws InterruptedException, ExecutionException {
RedisURI uri1 = RedisURI.Builder
.redis("ncp-4c4-000", 6379)
.build();
RedisURI uri2 = RedisURI.Builder
.redis("ncp-4c4-001", 6379)
.build();
RedisURI uri3 = RedisURI.Builder
.redis("ncp-4c4-002", 6379)
.build();
RedisPubSubAdapter<String, String> adapter = new RedisPubSubAdapter<>() {
@Override
public void message(String channel, String message) {
System.out.println("MSG Thread.currentThread().getName() = " + Thread.currentThread().getName());
System.out.println(message);
}
};
RedisClusterClient client1 = RedisClusterClient.create(Arrays.asList(uri1, uri2, uri3));
StatefulRedisClusterPubSubConnection<String, String> conn1 = client1.connectPubSub();
conn1.addListener(adapter);
RedisClusterPubSubAsyncCommands<String, String> cmd1 = conn1.async();
cmd1.subscribe("my-topic").get();
String s = cmd1.clientInfo().get();
System.out.println("s = " + s);
Thread.sleep(1000);
}
} I thought subscribe command change the default connection to subscriber-mode.
In Lettuce, how can handle situation like above? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Depends on the protocol version that you are using. Lettuce uses RESP3 by default, and RESP3 allows a single connection to be used for both subscriptions and issuing of commands. Does that help? |
Beta Was this translation helpful? Give feedback.
Depends on the protocol version that you are using.
Lettuce uses RESP3 by default, and RESP3 allows a single connection to be used for both subscriptions and issuing of commands.
RESP2 on the other hand does not and requires a dedicated connection for subscriptions.
Does that help?