options = {
'auth_pass': nconf.get('redis_pass')[nodeEnv],
'no_ready_check': true,
};
If I connect to redis with the redis-cli
tool it works just fine but for some reason i've been getting this error
29 Jun 2018 11:06:14.626136 <190>1 2018-06-29T18:06:14.346750+00:00 app web.1 - - ReplyError: NOAUTH Authentication required
at new Command (/app/node_modules/redis/lib/command.js:12:22)
at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at Socket.emit (events.js:208:7)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1173:10)Exception
Hard to tell from just your options
object but this is pretty standard and is known good. If I had to bet you're maybe connecting to the wrong redis server or nconf.get('redis_pass')[nodeEnv]
is supplying the wrong password (or maybe undefined).
Can you supply more of your code?
Hi, I have the same issue and I pass the password as a plain text and it stills send me the same error. In fact I only uncomment the line requirepass in the default redis.conf file, as I show in the following code:
# use a very strong password otherwise it will be very easy to break.
#
requirepass foobared
# Command renaming.
I make this configuration in my local machine in order to make the tests, but I am still get the same error:
events.js:160
throw er; // Unhandled 'error' event
^
ReplyError: Ready check failed: NOAUTH Authentication required.
at parseError (/home/mauricio/Documents/lisapp/pos_lisa/node_modules/redis/node_modules/redis-parser/lib/parser.js:193:12)
at parseType (/home/mauricio/Documents/lisapp/pos_lisa/node_modules/redis/node_modules/redis-parser/lib/parser.js:303:14)
Here is my code that I apply in my nodejs server:
const redisPassword = "foobared" ;
const ClientRedisApi = redis.createClient({
host : '127.0.0.1',
no_ready_check: true,
auth_pass: redisPassword,
});
ClientRedisApi.on('connect', () => {
global.console.log("connected");
})
ClientRedisApi.on('error', err => {
global.console.log(err.message)
})
ClientRedisApi.set("foo", 'bar');
ClientRedisApi.get("foo", function (err, reply) {
global.console.log(reply.toString())
})
The funny thing is that when I start the server, the key "foo" is saved in my redis database with the value "bar", but my app is crash and I can't do anything to interact with it.
To everyone here. I had the same problem when I tried to use a long password generated by the Linux random password generator. When I changed the password to something much shorter, everything worked fine. This may be a problem with this Node.JS package itself, because the long password did work if I went into redis-cli and used it with the auth command. However, the exact same password did not work when passed in during the createClient() method, regardless of what method variant I used (i.e. - full URL, or "auth_pass"/"password" in options block, or redisClient.auth() method - they all failed with the long password).
Hi @roschler, would you like to provide your code please. The truth is that I tried your suggestion and I am still having the same issue, not even with a password like '123'. I try with all the ways that are in the documentation and nothing different. I know that this can be bother to you but the true is that I don't have other choice. In advance thanks a lot.
@maooricio I'm 99.999% sure this is a misconfiguration at the server or the wrong server. Looking at your code from Oct 2018, I would try using a randomly generated key and echoing with MONITOR in redis-cli
.
I think that @roschler is having an entirely different issue (quoting?)
I still have this issue happened with me I have tried so many differents ways to connect with my redis db but password authntication failed for user
@nicollasmatheus what is your error?
I'm having the same error. I'm confident all the setting parameters are correct. I've tried all 3 methods and same error in all of them.
// First method
const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
client.auth(process.env.REDIS_PASSWORD);
// Second method
const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
password: process.env.REDIS_PASSWORD
});
// Third method
const client = redis.createClient(uri)
After settings NODE_DEBUG=redis
[0] Sending auth to redis:6379 id 0
[0] Send redis:6379 id 0: *2
[0] $4
[0] auth
[0] $14
[0] mypassword
[0]
[0] Stream connected redis:6379 id 0
[0] Redis: CONNECTED // CUSTOM MESSAGE
[0] Checking server ready state...
[0] Send redis:6379 id 0: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 0
[0] Redis server ready.
[0] on_ready called redis:6379 id 0
[0] Redis: READY // CUSTOM MESSAGE
[0] Stream connected redis:6379 id 1
[0] Checking server ready state...
[0] Send redis:6379 id 1: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 1
[0]
[0] /app/node_modules/redis/lib/command.js:12
[0] this.error = new Error();
[0] ^
[0] ReplyError: NOAUTH Authentication required.
[0] at new Command (/app/node_modules/redis/lib/command.js:12:22)
[0] at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
[0] at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
[0] at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
[0] at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
[0] at Object.onceWrapper (events.js:299:28)
[0] at Socket.emit (events.js:215:7)
[0] at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1115:10)
[0] npm ERR! code ELIFECYCLE
I'm using docker-compose
redis:
container_name: redis
image: redis:5.0.3-alpine
restart: always
env_file: .env
command: ["redis-server", "--appendonly", "yes", "--requirepass", "${REDIS_PASSWORD}"]
hostname: ${REDIS_HOST}
volumes:
- ~/.mydata/redis:/data
ports:
- ${REDIS_PORT}:6379
networks:
- my-network
and I can access to redis using cli redis-cli -h 127.0.0.1 -p 6379 -a 'mypassword'
@thellimist Check out what is happening with redis-cli
and MONITOR
, especially with your second method.
@stockholmux
export default class Cache {
static client: any
static init(): Promise<any> {
if (Cache.client) {
logger.error("Client already exists")
return new Promise((resolve, reject) => { reject() });
}
const client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, {
password: process.env.REDIS_PASSWORD
});
Cache.client = asyncRedis.decorate(client);
Cache.client.monitor(function (err, res) {
logger.info("Entering monitoring mode.");
});
Cache.client.set('foo', 'bar');
Cache.client.on("ready", (e: any) => {
logger.info(`ready ${e}`);
});
Cache.client.on("reconnecting", (e: any) => {
logger.info(`reconnecting ${e}`);
});
Cache.client.on("end", (e: any) => {
logger.info(`end ${e}`);
});
Cache.client.on("warning", (e: any) => {
logger.info(`warning ${e}`);
});
Cache.client.on("monitor", (e: any, res: any) => {
logger.error(`monitor err: ${e}`);
logger.info(`monitor res: ${res}`);
});
Cache.client.on("connect", () => {
logger.info("connected");
});
Cache.client.on("error", (e: any) => {
logger.error(`Error: :${e}`);
});
return new Promise((resolve, reject) => { resolve() }
}
and I call await Cache.init()
. Response is following:
[0] Sending auth to redis:6379 id 0
[0] Send redis:6379 id 0: *2
[0] $4
[0] auth
[0] $14
[0] mypassword
[0]
[0] Queueing monitor for next server connection.
[0] Queueing set for next server connection.
[0] Stream connected redis:6379 id 0
[0] 2019-12-17 06:49:48 error [server.ts]: connected
[0] Checking server ready state...
[0] Send redis:6379 id 0: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 0
[0] Redis server ready.
[0] on_ready called redis:6379 id 0
[0] Sending offline command: monitor
[0] Send redis:6379 id 0: *1
[0] $7
[0] monitor
[0]
[0] Sending offline command: set
[0] Send redis:6379 id 0: *3
[0] $3
[0] set
[0] $3
[0] foo
[0] $3
[0] bar
[0]
[0] 2019-12-17 06:49:48 info [server.ts]: ready undefined
[0] Net read redis:6379 id 0
[0] 2019-12-17 06:49:48 info [server.ts]: Entering monitoring mode.
[0] 2019-12-17 06:49:48 error [server.ts]: monitor err: 1576565388.385183
[0] 2019-12-17 06:49:48 info [server.ts]: monitor res: set,foo,bar
[0] Stream connected redis:6379 id 1
[0] Checking server ready state...
[0] Send redis:6379 id 1: *1
[0] $4
[0] info
[0]
[0] Net read redis:6379 id 1
[0]
[0] /app/node_modules/redis/lib/command.js:12
[0] this.error = new Error();
[0] ^
[0] ReplyError: NOAUTH Authentication required.
[0] at new Command (/app/node_modules/redis/lib/command.js:12:22)
[0] at RedisClient.info (/app/node_modules/redis/lib/individualCommands.js:169:39)
[0] at RedisClient.ready_check (/app/node_modules/redis/index.js:534:10)
[0] at RedisClient.on_connect (/app/node_modules/redis/index.js:428:14)
[0] at Socket.<anonymous> (/app/node_modules/redis/index.js:268:14)
[0] at Object.onceWrapper (events.js:299:28)
[0] at Socket.emit (events.js:215:7)
[0] at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1115:10)
Also key/val "foo: bar" is added to redis. So it connects correct initially then for some reason it tries to reconnect but fails. I only call await Cache.init()
once in express server.listen.
@thellimist I think you misunderstand - you need to run MONITOR
_from_ redis-cli
to properly diagnose these problems. Running it from within your application as above won't capture the authentication (because it happens before the MONITOR). I would also run it on a completely flushed DB.
Anyway, looking at your code (which I assume is a snippet), it really looks like somewhere else in your code you're calling redis.createClient
without the proper password (maybe another module even). I don't see the debug logs for reconnection and the id 1
says you're working on a different network stream.
@stockholmux
The issue was simple as you said. I was using typeorm package and it had a different config file which was not in js/ts file. Node Redis loge did not tell me where it was being called from made it hard to find.
Thanks.
If using Docker, edit your redis.conf's file network setting:
bind 0.0.0.0
That fixed it for me.
@mariothedev be SUPER careful with that. Without proper firewalls, your redis is wide open with using that bind
setting.
@stockholmux - thanks for letting me know :)
I'm also having this issue here.
Error message: ReplyError: NOAUTH Authentication required.
Version: Node Redis 3.0.0 / Redis 5.0.8
Came across this thread looking for an answer to the same problem. Wondering what the solution for this is.
One more possible resolution to add to the list. I was getting this error and it took me an embarrassingly long time to remember that I'm using Bull which is a Redis based queue. I'm also using Redis elsewhere in the application where I had been passing in the connection information, but forgot about Bull and was getting exactly these errors on the console.
So I guess one other thing to check is if anything else in your app is using Redis and might be firing back these errors.
edit If it is Bull that is causing this error for you, you must use password
in your redis connection object, not auth_pass
.
Most helpful comment
I'm also having this issue here.
Error message:
ReplyError: NOAUTH Authentication required.
Version: Node Redis 3.0.0 / Redis 5.0.8