一、实验环境:
1.服务器为centos6.4版本系统
2.redis安装版本为3.2.9
3.jedis版本为jedis-2.9.0
3.jedis依赖commons-pool包版本为commons-pool2-2.2.jar
二、Jedis操作集群java测试代码:
/**
*@throwsException
*redis3.x集群下的API存储
*/
@Test
publicvoidtest2()throwsException{
//创建集群中相应的节点对象,参数对应节点中的ip和端口号
HostAndPorth1 =newHostAndPort("192.168.8.150",7000);
HostAndPorth2 =newHostAndPort("192.168.8.150",7001);
HostAndPorth3 =newHostAndPort("192.168.8.150",7002);
HostAndPorth4 =newHostAndPort("192.168.8.150",7003);
HostAndPorth5 =newHostAndPort("192.168.8.150",7004);
HostAndPorth6 =newHostAndPort("192.168.8.150",7005);
Seths=newHashSet();
//依次放入set集合中
hs.add(h1);
hs.add(h2);
hs.add(h3);
hs.add(h4);
hs.add(h5);
hs.add(h6);
//将set集合创建集群对象
JedisClusterjc=newJedisCluster(hs);
//直接进行相应的操作,和jedis一致
jc.set("hxhaaj","哈哈啊哈");
jc.set("waj","哈哈啊哈");
jc.set("wangajiao","哈哈啊哈");
jc.set("ajiao","哈哈啊哈");
jc.set("hxh","哈哈啊哈");
jc.set("wang","哈哈啊哈");
jc.close();
}