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