Jedis连接集群
以maven项目为例:
1.配置pom.xml:
<dependencies> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.0.1</version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies>
2.主类:
public class RedisCluster { public static void main(String[] args) { Set<HostAndPort> jedisClusterSet = new HashSet<HostAndPort>(); jedisClusterSet.add(new HostAndPort("192.168.3.216", 6379)); JedisCluster jedisCluster = new JedisCluster(jedisClusterSet); jedisCluster.set("g", "gggg"); jedisCluster.lpush("h", "111","222","333","444"); System.out.println(jedisCluster.get("151")); } }