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. 成功

