How can i connect to a Redis
db that has username and password?
below is the code example i’m trying to use, ( i’m using nodejs
with node-redis
and Redis
version "redis": "^3.0.0",)
const client = redis.createClient({
host: "localhost",
port: 6379,
password: "1234",
username: "username"
});
2
Answers
Depends on the version of Node Redis that you are using. Since it looks like you are using Node Redis 3.x it would look like this:
You could also connect using a connection string:
Full documentation for 3.x is available on the tagged branch in the GitHub repo for Node Redis.
That said, I would recommend using Node Redis 4.x as it supports Promises, newer Redis commands, and many common Redis modules like RedisJSON and RediSearch.
To connect using 4.x:
or:
Details on connecting using Node Redis 4.x can be found in the README on the main branch of Node Redis and in the Client Configuration Guide.
To connect Nodejs Project with Redis Version ^4.x:
If you don’t Provide socket, password or username then by default it will connection on 127.0.0.1:6379
for by Default Connection use Beloved mention code
Redis Installation in system https://redis.io/docs/getting-started/installation/install-redis-on-windows/
For More information About redis as node package https://www.npmjs.com/package/redis
and For mode Redis Command https://redis.io/commands/