反编译查看Redis连接信息

代码如下:

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;


// region 代码调试:查看redis连接
try {
    Class redisUtilClass = RedisUtil.class;
    Field templateField = redisUtilClass.getDeclaredField("template");
    templateField.setAccessible(true);
    RedisTemplate template = (RedisTemplate)templateField.get(null);
    LettuceConnectionFactory connectionFactory = (LettuceConnectionFactory)template.getConnectionFactory();
    Field clientField = connectionFactory.getClass().getDeclaredField("client");
    clientField.setAccessible(true);
    RedisClient client = (RedisClient)clientField.get(connectionFactory);
    Field redisURIField = client.getClass().getDeclaredField("redisURI");
    redisURIField.setAccessible(true);
    RedisURI redisURI = (RedisURI)redisURIField.get(client);
    logTotalPrint.append(basePrintStr).append("Redis连接信息:").append(JSON.toJSONString(redisURI)).append(LINE_SEPARATOR_EXT);
} catch (Exception e) {
    StringWriter stringWriter = new StringWriter();
    e.printStackTrace(new PrintWriter(stringWriter));
    logTotalPrint.append(basePrintStr).append("获取Redis连接信息出现异常:").append(stringWriter.toString().replaceAll(LINE_SEPARATOR, LINE_SEPARATOR_EXT)).append(LINE_SEPARATOR_EXT);
}
// endregion

你可能感兴趣的:(#,Spring,redis,前端,mybatis)