Code -> GitHub
https://github.com/liufengji/redis_cli.git
@Test
public void connection() {
//连接本地的 Redis 服务
Jedis jedis = new Jedis("127.0.0.1",6379);
//查看服务是否运行,打出pong表示OK
System.out.println("connection is OK==========>: "+jedis.ping());
}
@Test
public void Jedis() {
Jedis jedis = new Jedis("192.168.67.143", 6379);
System.out.println(jedis.ping());
jedis.set("k1000", "v1000");
System.out.println(jedis.get("k1000"));
Set<String> keys = jedis.keys("*");
for (String string : keys) {
System.out.println(string);
}
jedis.close();
}
@Test
public static void JedisSet() {
Set<HostAndPort> nodes = new HashSet<HostAndPort>();
nodes.add(new HostAndPort("192.168.67.143", 6391));
@SuppressWarnings("resource")
JedisCluster jedisCluster = new JedisCluster(nodes);
jedisCluster.set("k1000", "v1000");
System.out.println(jedisCluster.get("k1000"));
}