redis多数据源
参考:https://zhuanlan.zhihu.com/p/595032370
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>6.1.6.RELEASE</version>
</dependency>
示例
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class T {
public static void main(String[] args) {
// 构建redis连接配置
RedisURI redisUri = RedisURI.builder()
.withHost("47.xxx.xxx.101")
.withPort(6379)
.withPassword("jtzlredis")
.withTimeout(Duration.of(10, ChronoUnit.SECONDS)).withDatabase(6)
.build();
// 创建客户端
RedisClient redisClient = RedisClient.create(redisUri);
// 获得连接对象
StatefulRedisConnection<String, String> connection = redisClient.connect();
// 异步命令
RedisCommands<String, String> commands = connection.sync();
// 测试
System.out.println(commands.ping());
// 发送命令
// commands
connection.close();
redisClient.shutdown();
}
}