码迷,mamicode.com
首页 > 其他好文 > 详细

redis4.0 集群,jedis客户端连接踩坑

时间:2018-01-21 20:37:10      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:客户端连接   word   nal   exce   beans   set   集群   函数   connect   

使用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="redis.clients.jedis.JedisPoolConfig"></bean>
    <bean class="com.s2s.common.jedis.JedisClientCluster" id="jedisCluster">
        <property name="jedisCluster" ref="jedisClusterOrginal"></property>
    </bean>

</beans>

 

redis4.0 集群,jedis客户端连接踩坑

标签:客户端连接   word   nal   exce   beans   set   集群   函数   connect   

原文地址:https://www.cnblogs.com/tdws/p/8325210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!