/**
* 集群版测试
*/
@Test
public void testJedisCluster() {
HashSet<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("192.168.102.130", 7001));
nodes.add(new HostAndPort("192.168.102.130", 7002));
nodes.add(new HostAndPort("192.168.102.130", 7003));
nodes.add(new HostAndPort("192.168.102.130", 7004));
nodes.add(new HostAndPort("192.168.102.130", 7005));
nodes.add(new HostAndPort("192.168.102.130", 7006));
JedisCluster cluster = new JedisCluster(nodes);
cluster.set("key1", "1000");
String string = cluster.get("key1");
System.out.println(string);
cluster.close();
}
1.systemctl stop firewalld
yum install -y iptables
yum install iptables-services
2.vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7002 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7003 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7004 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7005 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7006 -j ACCEPT
3.service iptables restart
* 集群版测试
*/
@Test
public void testJedisCluster() {
HashSet<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("192.168.102.130", 7001));
nodes.add(new HostAndPort("192.168.102.130", 7002));
nodes.add(new HostAndPort("192.168.102.130", 7003));
nodes.add(new HostAndPort("192.168.102.130", 7004));
nodes.add(new HostAndPort("192.168.102.130", 7005));
nodes.add(new HostAndPort("192.168.102.130", 7006));
JedisCluster cluster = new JedisCluster(nodes);
cluster.set("key1", "1000");
String string = cluster.get("key1");
System.out.println(string);
cluster.close();
}
1.systemctl stop firewalld
yum install -y iptables
yum install iptables-services
2.vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7002 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7003 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7004 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7005 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 7006 -j ACCEPT
3.service iptables restart
本文介绍了一种使用Java Jedis客户端库进行Redis集群连接和操作的方法。通过创建包含六个节点地址的HashSet集合,实现了与Redis集群的连接,并完成了简单的键值对设置与获取操作。此外,还提供了防火墙配置及端口开放的相关命令,确保Redis服务能够正常运行。
3515

被折叠的 条评论
为什么被折叠?



