Redis Learning (ii), Java operation Redis One, testing connectivity for Redis
1. Guide Package
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version></dependency>
2, write a Redisjava class test
package cn.qiuuuu.redis;import redis.clients.jedis.Jedis;public class RedisJava { public static void main(String[] args) { Jedis jedis = new Jedis("localhost"); System.out.println(jedis); System.out.println("连接成功"); System.out.println("服务正在运行:" + jedis.ping()); }}
The console output is:
[email protected]连接成功服务正在运行:PONG
II. testing the deposit of strings and strings into Redis
1. Guide Package
2. Write a class named Redisstringjava
package cn.qiuuuu.redis;import redis.clients.jedis.Jedis;public class RedisStringJava { public static void main(String[] args) { // 连接本地的 Redis 服务 Jedis jedis = new Jedis("localhost"); System.out.println("连接成功"); // 设置 redis 字符串数据 jedis.set("runoobkey", "www.runoob.com"); // 获取存储的数据并输出 System.out.println("redis 存储的字符串为: " + jedis.get("runoobkey")); }}
The console output is:
连接成功redis 存储的字符串为: www.runoob.com
Redis Learning (ii), Java operation Redis