首页 > 代码库 > Java操作 Redis 集群

Java操作 Redis 集群

// 连接redis集群    @Test    public void testJedisCluster() {        JedisPoolConfig config = new JedisPoolConfig();        // 最大连接数        config.setMaxTotal(30);        // 最大连接空闲数        config.setMaxIdle(2);        //集群结点        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();        jedisClusterNode.add(new HostAndPort("192.168.101.3", 7001));        jedisClusterNode.add(new HostAndPort("192.168.101.3", 7002));        jedisClusterNode.add(new HostAndPort("192.168.101.3", 7003));        jedisClusterNode.add(new HostAndPort("192.168.101.3", 7004));        jedisClusterNode.add(new HostAndPort("192.168.101.3", 7005));        jedisClusterNode.add(new HostAndPort("192.168.101.3", 7006));        JedisCluster jc = new JedisCluster(jedisClusterNode, config);                JedisCluster jcd = new JedisCluster(jedisClusterNode);        jcd.set("name", "zhangsan");        String value = jcd.get("name");        System.out.println(value);    }

 

Java操作 Redis 集群