redis4.0 集羣,jedis客戶端鏈接配置

本文版權歸博客園和做者吳雙本人共同全部 轉載和爬蟲請註明原文地址 www.cnblogs.com/tdwsredis

使用jedis 2.9.0鏈接,異常信息:spring

redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set。apache

說我沒有設置密碼,當時我就震驚了。我明明設置了密碼呀。我用redis-cli鏈接的時候 還讓我輸入密碼了呢~函數

檢查了很久纔想起來,redis-cli默認鏈接6379,我只給6379設置密碼了,實際上要給每一個節點都設置密碼:ui

config set masterauth abc  
config set requirepass abc  

 

spring配置,jedis鏈接集羣,居然沒有RedisCluster一個構造函數的參數只由 Set<HostAndPort>和password組成,害得我還要配置這麼多參數。spa

<?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>
相關文章
相關標籤/搜索