Node-Redis: ready check failed - NOAUTH Authentication required

Enthusiastic Developer picture Enthusiastic Developer · Aug 14, 2017 · Viewed 13.1k times · Source

I have a strange redis behavior:

const redis = require('redis');
const { REDIS_URL: redisUrl, REDIS_PASSWORD: redisPassword } = process.env;

const client = redis.createClient(redisUrl, {
  no_ready_check: true,
  auth_pass: redisPassword
});

client.on('connect', () => {
  redisPassword && client.auth(redisPassword);
});

client.on('error', err => {
  global.console.log(err.message)
});

But all the time I receive following error:

throw er; // Unhandled 'error' event

ReplyError: Ready check failed: NOAUTH Authentication required.

Why unhandled ? I set onerror handler
Why Ready check failed ? I disabled it in options

Answer

GuangshengZuo picture GuangshengZuo · Aug 15, 2017

I'm not sure why your code will throw this error. But I try this code in my local machine, it works well.

const redis = require('redis');
const redisPassword = "password" ; 
const client = redis.createClient({
          host : '127.0.0.1',  
          no_ready_check: true,
          auth_pass: redisPassword,                                                                                                                                                           
});                               
                                  
client.on('connect', () => {   
          global.console.log("connected");
});                               
                                  
client.on('error', err => {       
          global.console.log(err.message)
});                               
                                  
client.set("foo", 'bar');         
                                  
client.get("foo", function (err, reply) {
        global.console.log(reply.toString())
})

And run node client.js will output :

connected

bar

NOAUTH Authentication required is caused by when redis process command , it found the client is not authenticated so it complained with it.

I guess maybe the redisUrl you give to createClient has some problem, try to debug it or change to my code's way to try. Hopefully you can fix it.

And one more thing: the client.auth(redisPassword) is not necessary because if you set an auth_pass or password option, the redis client will auto send auth command to server before any command.