2

Edit: After thinking about the issue, the real question is what is an example of connecting to digitalocean's managed redis with node-redis using tls?

I'm able to connect just fine with redisinsight GUI client using username / password, but cannot connect with nodejs. It's on the same computer so no firewall issues.

var redis = require('redis');
var client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_URL, {no_ready_check: true});
client.auth('password', function (err) {
    if (err) {
      console.log(err);
      return
    }
    console.log('auth')
});

One thing I'm confused about is where to enter the username? It's just 'default' but the documentation for node_redis doesn't provide a way to give a username during auth.

Error is: AbortError: Redis connection lost and command aborted. It might have been processed.

Here's my working lightly anonymized redisinsight connection screen.

How do I do the same in node-redis?

enter image description here

Harry
  • 52,711
  • 71
  • 177
  • 261
  • Just curious: Could you try this way to create a client `createClient(port, host, {auth_pass: password, tls: {servername: host}})`? Maybe the `tls` option is required. – manishg Aug 19 '20 at 01:45
  • 1
    @manishg still get the same problem with that. – Harry Aug 20 '20 at 14:27

1 Answers1

4

The AUTH command, as stated in the docs:

When ACLs are used, the single argument form of the command, where only the password is specified, assumes that the implicit username is "default".

So even if you are using Redis 6, where additional users are supported, your authentication for default should work.

The error you're seeing is the result of a broken connection, e.g. you somehow lost connection with the Redis server. node-redis is dealing with one of two scenarios (or both) - the connection has timed out or the the reconnect attempts have exceeded the maximum number specified in a config. I would double check your connection information and how your redis server is configured.

I see you are using TLS, you may find this useful: Securing Node Redis

If you want to authenticate node-redis client with a different user, when using Redis 6, you will have to use send_command, but before you need to remove the current AUTH command, as currently node-redis doesn't support the new command AUTH <username> <password>.

client['auth'] = null;
client.send_command('AUTH', ['<username>', '<password>'], redis.print);
LeoMurillo
  • 6,048
  • 1
  • 19
  • 34
  • Thanks, it's a database as a service https://www.digitalocean.com/products/managed-databases-redis/ so I don't have access to the redis conf. When I see "too many reconnection attempts" I assume this is because the connection failed and it reconnecting too much as a result? What's the correct way to connect with tls in node-redis? – Harry Aug 16 '20 at 10:02
  • I think it is probably because of the TLS-enabled you show in the screenshot. I'd say try this Digital Ocean tutorial first: https://www.digitalocean.com/community/tutorials/how-to-connect-to-managed-redis-over-tls-with-stunnel-and-redis-cli. Once you can connect with redis-cli, try the `{auth_pass: 'password', tls: {servername: 'location.of.server'}}` configuration for node-redis mentioned in https://stackoverflow.com/questions/31947527/securing-node-redis – LeoMurillo Aug 16 '20 at 22:29
  • Thanks though that doesn't make a difference for me. The answer might be outdated as I don't see auth_pass in any documentation for node-redis. It's just 'password' now. – Harry Aug 18 '20 at 02:22
  • Were you able to connect with redis-cli? Once you've done that you can try setting up your node app the same way as redis-cli. – LeoMurillo Aug 18 '20 at 14:46
  • I'm just going to accept you to thank you for the effort, the answer was specific to my env. – Harry Aug 20 '20 at 19:45