7

I'm using redis with nodejs. Version: "redis": "^3.1.2"

When my server connects to redis, I get the following error:

ERR wrong number of arguments for 'auth' command

I'm guessing it has something to do with the URL, which looks like this:

redis://h:<password>@<url>:<port>

My redis is hosted by Heroku and I'm unable to change the URL. And have no idea how can I make it work. Any ideas/solutions much appreciated.

denislexic
  • 10,786
  • 23
  • 84
  • 128
  • 3
    Redis 3.1.2 has breaking changes. Above URL works till redis@^3.0.2 – Ritesh Kumar Gupta May 20 '21 at 07:59
  • 4
    Here is the release note from Heroku: https://devcenter.heroku.com/changelog-items/1932 . Please remove the username from the URL string present in the env variable of Heroku. It should look like redis://password_goes_here@host_goes_here:port_goes_here – Ritesh Kumar Gupta May 20 '21 at 08:06

1 Answers1

21

Redis Version < 6.0.0 and node-redis >=3.1.0 , redis://h:<password>@<url>:<port> will not work and throw ERR wrong number of arguments for 'auth' command.

Solution: redis://:<password>@<url>:<port> works ie: remove username from the URL. Note:- The ":" before the <password>

This should fix the problem that you are facing.

For other versions:

Redis Version < 6.0.0 and node-redis <=3.0.2 , redis://h:<password>@<url>:<port> works.

Redis Version >= 6.0.0 and node-redis(any version), both redis://<username>:<password>@<url>:<port>(when username in redis ACL is set to custom username) and redis://<password>@<url>:<port> will work.

The reason is:

  • node-redis made the changes to support Redis-6, as per releasenote.

  • Redis-6 supports username in ALC. Before v6, Redis did not include the notion of users, and the only authentication strategy was a single login password. Reference

  • Whenever you attach Redis addon to Heroku container, the environment variable REDIS_URL is set and the value is Connection URL of format: redis://h:<password>@<url>:<port>. This "h" is a fake/dummy/placeholder username because some clients(eg: node-redis) could not correctly handle a blank username in the URL. After the release of ACLs in Redis 6, clients began to support the new AUTH command that uses 2 arguments (username and password). Clients that attempt to pass the h username to the AUTH will result in an above error on Redis versions 4 and 5. Reference

Ritesh Kumar Gupta
  • 5,055
  • 7
  • 45
  • 71
  • 1
    Thank you. For others that might see this, I did a simple regex to remove the "h" in the URL provided by Heroku. – denislexic May 20 '21 at 15:39
  • 2
    We just ran into this because `promise-redis` (would not recommend at this point), includes `node-redis` with a `*` dependency resolution. We are running Redis 5.0 right now, and so the update from 3.0 to 3.1 in a completely unrelated change broke our AUTH commands with a username within it. Thanks for the awesome explanation! – Matt Forster May 20 '21 at 21:02
  • 7
    Just a comment, Solution: `redis://@:` works ie: remove username from the URL. should be: Solution: `redis://:@:` works ie: remove username from the URL. You need a `:` before the password. – shernshiou Dec 07 '21 at 13:04
  • 2
    @shernshiou you are right this: `redis://:@:` worked well for me – OBI PASCAL BANJUARE Mar 03 '22 at 13:38