本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws
使用jedis 2.9.0连接,异常信息:
redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set。
说我没有设置密码,当时我就震惊了。我明明设置了密码呀。我用redis-cli连接的时候 还让我输入密码了呢~
检查了好久才想起来,redis-cli默认连接6379,我只给6379设置密码了,实际上要给每个节点都设置密码:
config set masterauth abc
config set requirepass abc
spring配置,jedis连接集群,竟然没有RedisCluster一个构造函数的参数只由 Set<HostAndPort>和password组成,害得我还要配置这么多参数。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<context:property-placeholder location="classpath:conf/redis.properties"/>
<!--cluster版本-->
<bean class="redis.clients.jedis.JedisCluster" id="jedisClusterOrginal">
<constructor-arg name="jedisClusterNode">
<set>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${IP}"/>
<constructor-arg index="1" value="6379"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${IP}"/>
<constructor-arg index="1" value="6380"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${IP}"/>
<constructor-arg index="1" value="6381"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${IP}"/>
<constructor-arg index="1" value="6382"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${IP}"/>
<constructor-arg index="1" value="6383"/>
</bean>
<bean class="redis.clients.jedis.HostAndPort">
<constructor-arg index="0" value="${IP}"/>
<constructor-arg index="1" value="6384"/>
</bean>
</set>
</constructor-arg>
<constructor-arg name="connectionTimeout" value="10000"></constructor-arg>
<constructor-arg name="soTimeout" value="10000"></constructor-arg>
<constructor-arg name="maxAttempts" value="100"></constructor-arg>
<constructor-arg name="password" value="${pwd}"></constructor-arg>
<constructor-arg name="poolConfig" ref="jedisPoolConfig">
</constructor-arg>
</bean>
<bean id="jedisPoolConfig" class="org.apache.commons.pool2.impl.GenericObjectPoolConfig">
<!--<property name="maxIdle" value="8"></property>-->
<!--<property name="maxTotal" value="8"></property>-->
<!--<property name="minIdle" value="0"></property>-->
</bean>
<bean class="com.s2s.common.jedis.JedisClientCluster" id="jedisCluster"> <property name="jedisCluster" ref="jedisClusterOrginal"></property> </bean> </beans>