ERR Client sent AUTH, but no password is set
Asked Answered
F

3

20

I am using jedis 2.8.0 and getting following exception:

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
        at redis.clients.jedis.Protocol.processError(Protocol.java:123)
        at redis.clients.jedis.Protocol.process(Protocol.java:157)
        at redis.clients.jedis.Protocol.read(Protocol.java:211)
        at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
        at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:196)
        at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2049)
        at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:89)
        at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:458)
        at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
        at redis.clients.util.Pool.getResource(Pool.java:49)
        ... 4 more

Following is the api I am using:

jedisPool = new JedisPool(jedisPoolConfig, host, port, IDLE_CONNECTION_TIMEOUT, authSecret); 

Notes:

  1. I am able to successfully send commands to redis using the exact same password using the redis-cli -a option.
  2. I also printed the password in the logs to see if I am sending wrong password, but the password passed to JedisPool is proper.
  3. I also tried to "redis-cli monitor" calls on redis but I dont see any AUTH request.
Fearful answered 16/6, 2017 at 21:32 Comment(0)
E
21

There is no password set in your Redis instance. Password sent with redis-cli -a is just being ignored.

Now, you may set the password in redis instance. To do so, edit redis configuration file, set requirepass option and restart redis instance.

Or, just ignore password option while communicating with redis. E.g.

jedisPool = new JedisPool(jedisPoolConfig, host, port, IDLE_CONNECTION_TIMEOUT);
Eberly answered 17/6, 2017 at 4:30 Comment(1)
Thats correc. I was using multiple redis layers..in one layer AUTH was enabled and another not.Fearful
G
4

This will might work if you don't want to set the password. enter image description here

spring.redis.host=127.0.0.1 
spring.redis.port=6379 
spring.redis.password=

Leave the password field as blank.

OR

Use the requirepass a password option

redis 127.0.0.1:6379> AUTH PASSWORD

(error) ERR Client sent AUTH, but no password is set.

redis 127.0.0.1:6379> CONFIG SET requirepass "mypass"

OK

redis 127.0.0.1:6379> AUTH mypass

OK

Gadoid answered 8/6, 2020 at 12:22 Comment(1)
Didn't work for me using Jedis. Leaving the password empty still caused the same exception. What worked for me is just configuring the password using requirepass in the redis.confPreachment
M
1

A few need to have password in some environments and not to have password in some environments. This hack will work for you.

public JedisConnection(JedisConfig jedisConfig) {
    JedisPoolConfig poolConfig = buildPoolConfig();
    String password = jedisConfig.getRedisPassword();
    if (password != null && password.isEmpty()) {
        password = null;
    }
    jedisPool = new JedisPool(
        poolConfig,
        jedisConfig.getRedisHost(),
        jedisConfig.getRedisPort(),
        jedisConfig.getRedisTimeOut(),
        password
    );
}

In this version of the constructor, the JedisPool is created similarly regardless of whether a password is provided. If the password is null or empty, null is passed as the password argument to the JedisPool constructor, equivalent to not passing a password. This way, you can handle both password and no-password cases in a cleaner way :)

Monopetalous answered 30/5 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.