使用身份验证用户名/密码nodejs连接到托管Redis

使用身份验证用户名/密码nodejs连接到托管Redis

问题描述:

编辑:考虑了这个问题之后,真正的问题是,使用tls通过node-redis连接到digitalocean的托管redis的例子是什么?

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?

我能够连接使用用户名/密码与redisinsight GUI客户端很好,但是不能与nodejs连接。它在同一台计算机上,因此没有防火墙问题。

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')
});

我很困惑的一件事是在哪里输入用户名?只是默认,但是node_redis的文档没有提供在身份验证期间提供用户名的方法。

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.

错误是: AbortError:Redis连接丢失并且命令丢失流产了。

这是我正在工作的匿名匿名reisinsight连接屏幕。

Here's my working lightly anonymized redisinsight connection screen.

我该怎么做在node-redis中?

How do I do the same in node-redis?

AUTH 命令,如文档中所述


使用ACL时,仅指定密码的命令的单参数形式
假定隐式用户名是默认。

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

因此,即使您使用支持其他用户的Redis 6,您对 default 应该可以。

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

您看到的错误是由于断开的连接造成的,例如您以某种方式失去了与Redis服务器的连接。 node-redis 正在处理以下两种情况之一(或同时存在)-连接超时或重新连接尝试超过配置中指定的最大数目。我将仔细检查您的连接信息以及Redis服务器的配置方式。

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.

我看到您正在使用TLS,您可能会发现此有用:保护节点Redis

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

如果您想使用其他用户对node-redis客户端进行身份验证,则在使用Redis 6时,您将必须使用 send_command ,但是在您需要删除当前的 AUTH 命令之前,因为当前node-redis不支持新命令 AUTH< username> <密码>

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);