【依賴】
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.3.2</version> </dependency>
【代碼】
import redis.clients.jedis.Jedis; .... //連接本地的 Redis 服務 Jedis jedis = new Jedis("192.168.32.128"); jedis.auth("123456"); System.out.println("連接成功"); //設置 redis 字符串數據 jedis.set("wto", "www.wto.com"); // 獲取存儲的數據並輸出 System.out.println("redis 存儲的字符串為: "+ jedis.get("wto"));
以上紅色粗體為關鍵
【輸出】
連接成功
redis 存儲的字符串為: www.wto.com
參考資料:
https://www.runoob.com/redis/redis-java.html
END