如何使用Jedis连接Redis
1.1 导入需要的依赖
<dependencies>
<!-- 1、Jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.1</version>
</dependency>
<!-- 2、 Junit测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- 3、 Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
</dependencies>
1.2 测试
import redis.clients.jedis.Jedis;
public class TestJedisConnection {
// Redis服务器信息
private static final String REDIS_HOST = "192.168.200.141";
private static final int REDIS_PORT = 6379;
private static final String REDIS_PASSWORD = "sl183691";
public static void main(String[] args) {
//1. 连接Redis
Jedis jedis = new Jedis(REDIS_HOST, REDIS_PORT);
jedis.auth(REDIS_PASSWORD);
//2. 操作Redis - Redis的命令是什么,Jedis的方法就是什么
jedis.set("city", "Shanghai");
//2. 获取操作结果
String value = jedis.get("city");
System.out.println(value);
//3. 释放资源
jedis.close();
}
}
测试结果:
原文地址:https://blog.csdn.net/weixin_39033358/article/details/144005437
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!