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

使用哨兵模式连接redis连接池时,遇到错误:

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

发现是redis没有设置密码,程序却发送了auth选项。

工程里JedisSentinelPool是通过spring配置的:

    <bean id="jedisPool" class="redis.clients.jedis.JedisSentinelPool" destroy-method="destroy">
        <constructor-arg value="${redis.master}" />
        <constructor-arg>
            <set>
                <value>${redis.host}:${redis.port}</value>
            </set>
        </constructor-arg>
        <constructor-arg ref="jedisPoolConfig" />
        <constructor-arg value="${redis.timeout}"/>
    </bean>

发现JedisSentinelPool的构造方法有2个类似的:
	public JedisSentinelPool(String masterName, Set sentinels,
			GenericObjectPoolConfig poolConfig, int timeout) {
		this(masterName, sentinels, poolConfig, timeout, null, 0);
	}

	public JedisSentinelPool(String masterName, Set sentinels,
			GenericObjectPoolConfig poolConfig, String password) {
		this(masterName, sentinels, poolConfig, 2000, password);
	}

JedisSentinelPool初始化构造方法的入参是根据spring配置文件的参数配置顺序加载的,JedisSentinelPool使用了第二个构造方法,导致上面的错误。

解决方法,给配置文件的参数配置name属性.

    <bean id="jedisPool" class="redis.clients.jedis.JedisSentinelPool" destroy-method="destroy">
        <constructor-arg name="masterName" value="${redis.master}" />
        <constructor-arg name="sentinels">
            <set>
                <value>${redis.host}:${redis.port}</value>
            </set>
        </constructor-arg>
        <constructor-arg name="poolConfig" ref="jedisPoolConfig" />
        <constructor-arg  name="timeout" value="${redis.timeout}"/>
    </bean>

问题解决


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/c295477887/article/details/52384542
个人分类: redis
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭