I did a simple test and prove lettuce does send AUTH after reconnection.
Just run config set 2
in redis cli, and set LOG level to TRACE
so that all commands will be printed out.
@Test
public void should_reconnect_send_auth() {
RedisURI redisURI = RedisURI.builder().withHost("localhost").build();
RedisClient client = RedisClient.create(redisURI);
StatefulRedisConnection<String, String> conn = client.connect();
RedisCommands<String, String> sync = conn.sync();
sync.auth("pwd4unittests");
sync.hmset("my_id", ImmutableMap.of("feature_1", "value_1"));
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
List<KeyValue<String, String>> results = sync.hmget("my_id", "feature_1");
System.out.println(results);
}
The log shows that
[2021-01-12T18:38:30,121Z](lettuce-eventExecutorLoop-1-1)([]) INFO - ConnectionWatchdog - Reconnecting, last destination was localhost/127.0.0.1:6379
[2021-01-12T18:38:30,124Z](lettuce-eventExecutorLoop-1-1)([]) DEBUG - RedisClient - Resolved SocketAddress localhost:6379 using RedisURI [host='localhost', port=6379]
[2021-01-12T18:38:30,125Z](lettuce-eventExecutorLoop-1-1)([]) DEBUG - ReconnectionHandler - Reconnecting to Redis at localhost:6379
[2021-01-12T18:38:30,136Z](lettuce-nioEventLoop-4-2)([]) DEBUG - CommandHandler - [channel=0xc3ac6a89, [id: 0x51428352] (inactive), chid=0x2] channelRegistered()
[2021-01-12T18:38:30,138Z](lettuce-nioEventLoop-4-2)([]) DEBUG - CommandHandler - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, chid=0x2] channelActive()
[2021-01-12T18:38:30,138Z](lettuce-nioEventLoop-4-2)([]) DEBUG - DefaultEndpoint - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, epid=0x1] activateEndpointAndExecuteBufferedCommands 0 command(s) buffered
[2021-01-12T18:38:30,138Z](lettuce-nioEventLoop-4-2)([]) DEBUG - DefaultEndpoint - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, epid=0x1] activating endpoint
[2021-01-12T18:38:30,139Z](lettuce-nioEventLoop-4-2)([]) DEBUG - RedisChannelHandler - dispatching command AsyncCommand [type=AUTH, output=StatusOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.Command]
[2021-01-12T18:38:30,140Z](lettuce-nioEventLoop-4-2)([]) DEBUG - DefaultEndpoint - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, epid=0x1] write() writeAndFlush command ActivationCommand [type=AUTH, output=StatusOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.AsyncCommand]
[2021-01-12T18:38:30,140Z](lettuce-nioEventLoop-4-2)([]) DEBUG - CommandHandler - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, chid=0x2] write(ctx, ActivationCommand [type=AUTH, output=StatusOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.AsyncCommand], promise)
[2021-01-12T18:38:30,141Z](lettuce-nioEventLoop-4-2)([]) DEBUG - CommandEncoder - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379] writing command ActivationCommand [type=AUTH, output=StatusOutput [output=null, error='null'], commandType=io.lettuce.core.protocol.AsyncCommand]
[2021-01-12T18:38:30,141Z](lettuce-nioEventLoop-4-2)([]) TRACE - CommandEncoder - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379] Sent: *2
$4
AUTH
$13
my_password
[2021-01-12T18:38:30,141Z](lettuce-nioEventLoop-4-2)([]) DEBUG - DefaultEndpoint - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, epid=0x1] write() done
[2021-01-12T18:38:30,142Z](lettuce-nioEventLoop-4-2)([]) DEBUG - DefaultEndpoint - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, epid=0x1] flushCommands()
[2021-01-12T18:38:30,142Z](lettuce-nioEventLoop-4-2)([]) DEBUG - DefaultEndpoint - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, epid=0x1] flushCommands() Flushing 0 commands
[2021-01-12T18:38:30,142Z](lettuce-nioEventLoop-4-2)([]) DEBUG - ConnectionWatchdog - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, last known addr=localhost/127.0.0.1:6379] channelActive()
[2021-01-12T18:38:30,142Z](lettuce-nioEventLoop-4-2)([]) DEBUG - CommandHandler - [channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379, chid=0x2] channelActive() done
[2021-01-12T18:38:30,142Z](lettuce-nioEventLoop-4-2)([]) INFO - ReconnectionHandler - Reconnected to localhost:6379, Channel channel=0xc3ac6a89, /127.0.0.1:60446 -> localhost/127.0.0.1:6379