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.
Starting Redis By default, the port is 6379 and there is no password.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With