springboot 使用 jedis 连接 Redis 数据库
1. 在 pom.xml 配置文件中添加依赖

<!-- redis 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- jedis 依赖 -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
2. 编写测试方法

@Test void redisTest(){ // 连接 Redis 数据库 , 获取连接对象 Jedis jedis = new Jedis("localhost"); // 向 Redis 数据库写入数据 jedis.set("name","李四"); // 读取 Redis 数据库数据 String name = jedis.get("name"); // 打印输出 System.out.println(name); }
3. 成功


浙公网安备 33010602011771号