1.修改redis.config文件
# 开启日志
loglevel debug
2. 开启日志
2.1 RedisSion客户端
logback.xml
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <logger name="org.redisson" level="DEBUG" additivity="false"> <appender-ref ref="CONSOLE" /> </logger>
3 查看日志
.............
2025-02-26 13:08:46.732 | DEBUG 23436 | http-nio-48080-exec-3 [TID: N/A] org.redisson.command.RedisExecutor | acquired connection for command (SETEX) and params [[111, 97, 117, 116, 104, 50, 95, 97, 99, 99, ...], 1799, [123, 34, 99, 114, 101, 97, 116, 101, 84, 105, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using node .../...:6379... RedisConnection@1510563801 [redisClient=[addr=redis://...:6379], channel=[id: 0x665e6448, L:/192.168.1.3:61694 - R:.../...:6379], currentCommand=null, usage=1]
# 使用 SETEX 命令存储数据到 Redis,参数包括键(字节数组形式)、过期时间(1799秒≈30分钟)和值(JSON 数据)
2025-02-26 13:08:46.739 | DEBUG 23436 | redisson-netty-1-5 [TID: N/A] org.redisson.command.RedisExecutor | connection released for command (SETEX) and params [[111, 97, 117, 116, 104, 50, 95, 97, 99, 99, ...], 1799, [123, 34, 99, 114, 101, 97, 116, 101, 84, 105, ...]] from slot NodeSource [slot=0, addr=null, redisClient=null, redirect=null, entry=null] using connection RedisConnection@1510563801 [redisClient=[addr=redis://...:6379], channel=[id: 0x665e6448, L:/192.168.1.3:61694 - R:.../...:6379], currentCommand=CommandData [promise=java.util.concurrent.CompletableFuture@766aeb31[Completed normally], command=(SETEX), params=[[111, 97, 117, 116, 104, 50, 95, 97, 99, 99, ...], 1799, [123, 34, 99, 114, 101, 97, 116, 101, 84, 105, ...]], codec=org.redisson.client.codec.StringCodec], usage=0]
# 操作完成后,连接被释放回连接池,避免资源泄漏。
.............
2025-02-26 13:08:54.522 | DEBUG 23436 | redisson-netty-1-8 [TID: N/A] o.r.connection.IdleConnectionWatcher | Connection [id: 0x845c8279, L:/192.168.1.3:61695 ! R:.../...:6379] has been closed due to idle timeout. Not used for 17259 ms
2025-02-26 13:08:54.522 | DEBUG 23436 | redisson-netty-1-14 [TID: N/A] o.r.connection.IdleConnectionWatcher | Connection [id: 0xe8694cab, L:/192.168.1.3:61698 ! R:.../...:6379] has been closed due to idle timeout. Not used for 17259 ms
# Redisson 连接池检测到多个空闲超过约 16 秒的连接,自动关闭它们以释放资源。
.............