1.maven依赖:java
<dependency>node
<groupId>redis.clients</groupId>redis
<artifactId>jedis</artifactId>spring
<version>2.8.1</version>apache
</dependency>maven
2.增长spring 配置tcp
3.增长connect-redis.properties 配置文件ide
这里配置了6个节点this
4.增长java类:spa
Java代码
5.到此配置完成,使用时,直接注入便可, 以下所示:
@Autowired
JedisCluster jedisCluster;
注意:“no reachable node in cluster] with root cause”报错
(1)若是redis集群不是部署在本机,是部署在其它机器或者虚拟机上,必定注意redis.conf配置文件中的bind ip不要使用127.0.0.1,而是改为机器的ip地址,否则将没法访问redis集群,会由于找不到redis集群报这样的错误;
同时防火墙开放端口
$ iptables -I INPUT -p tcp --dport 7000 -j ACCEPT $ iptables -I INPUT -p tcp --dport 7001 -j ACCEPT $ iptables -I INPUT -p tcp --dport 7002 -j ACCEPT $ iptables -I INPUT -p tcp --dport 7003 -j ACCEPT $ iptables -I INPUT -p tcp --dport 7004 -j ACCEPT $ iptables -I INPUT -p tcp --dport 7005 -j ACCEPT
(2)查看是否关闭了防火墙,若是没有关闭防火墙,利用以下命令关闭防火墙:
1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables start 关闭: service iptables stop