I’m trying to connect aws Redis Cache via NodeJS, however, it fails with the below error. But I’m able to successfully connect via redis-cli.
Node Js File
Command: node app.js
node version: v16.14.0
aws redis engine version: 7.0.7
app.js
`const redis = require(‘redis’);
const { promisify } = require(‘util’);
console.log(‘hello’);
const redisClient = redis.createClient({
socket: {
host: “master.dev.xxx.use1.cache.amazonaws.com”,
port: 6379,
tls:true,
reconnectStrategy: function () {
const retries = 35000;
return retries;
},
password: “znIKmEB1yBuNcM3urRtp”,
}
});
const connect = promisify(redisClient.connect).bind(redisClient);
connect()
.then(() => {
console.log(“connected successfully”);
})
.catch((error) => {
console.log(error);
});
redisClient.on(‘error’, (err) => {
console.log(err);
});
// Example: Setting a key
redisClient.set(‘Finalli’, ‘value’, redis.print);
// Example: Getting a key
redisClient.get(‘key’, function(err, reply) {
console.log(‘Value: ‘ + reply);
});`
ERROR RECEIVED:
`node app.js
hello
node:internal/process/promises:265
triggerUncaughtException(err, true /* fromPromise */);
^
[ErrorReply: NOAUTH Authentication required.]`
I’m able to connect via redis-cli successfully though.
`redis-cli -h master.dev.xxx.use1.cache.amazonaws.com -p 6379 –tls
AUTH XXX
OK
set one 1
OK
keys *
- “one”`
Could you please help ?