Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis: ERR wrong number of arguments for 'auth' command

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.

like image 801
denislexic Avatar asked May 20 '21 03:05

denislexic


People also ask

What is Redis default password?

Starting Redis By default, the port is 6379 and there is no password.


1 Answers

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.

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

like image 161
Ritesh Kumar Gupta Avatar answered Oct 26 '22 19:10

Ritesh Kumar Gupta