Redis从入门到精通-redis-集群的Jedis开发
package com.mangoubiubiu; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisCluster; public class JqJedisOperate { public static void main(String[] args) { HostAndPort hostAndPort = new HostAndPort("192.168.117.134", 6379); //集群随便连接哪个节点都行 JedisCluster jedisCluster=new JedisCluster(hostAndPort); jedisCluster.set("name","小明"); String name = jedisCluster.get("name"); System.out.println(name); jedisCluster.close(); } }
或者
public class JedisClusterTest { public static void main(String[] args) { Set<HostAndPort>set =new HashSet<HostAndPort>(); set.add(new HostAndPort("192.168.31.211",6379)); JedisCluster jedisCluster=new JedisCluster(set); jedisCluster.set("k1", "v1"); System.out.println(jedisCluster.get("k1")); } }