1.开启Redis
[root@localhost redis-6.2.6]# src/redis-server redis.conf
2.添加依赖
3.编写Java代码
public class lettuceDemo {
public static void main(String[] args) {
//注意:密码写在连接地址中
RedisClient redisClient = RedisClient.create("redis://123@192.168.140.128");
StatefulRedisConnection<String, String> connect = redisClient.connect();
RedisCommands<String, String> sync = connect.sync();
String name = sync.get("name");
System.out.println("name = " + name);
}
}
4.运行