本文版權歸部落格園和作者吳雙本人共同所有 轉載和爬蟲請注明原文位址 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>