I'm using Redis To Go in combination with the https://github.com/mranney/node_redis library. Redis gives me a url that looks like redis://me:[email protected]:9393
but I don't know how to use it as createClient()
only takes the host and the port.
I believe that the scheme for the URL you have is:
redis://username:password@host:port
.
I don't believe username
is used. node_redis
provides two methods that you'll use to log in: createClient
and auth
. There are details in the readme, but for reference here is the relevant portion:
redis.createClient(port, host, options)
Create a new client connection.
port
defaults to6379
andhost
defaults to127.0.0.1
. If you haveredis-server
running on the same computer as node, then the defaults for port and host are probably fine.options
in an object with the following possible properties:
parser
: which Redis protocol reply parser to use. Defaults tohiredis
if that module is installed. This may also be set tojavascript
.return_buffers
: defaults to false. If set totrue
, then bulk data replies will be returned as node Buffer objects instead of JavaScript Strings.
createClient()
returns aRedisClient
object that is namedclient
in all of the examples here.client.auth(password, callback)
When connecting to Redis servers that require authentication, the
AUTH
command must be sent as the first command after connecting. This can be tricky to coordinate with reconnections, the ready check, etc. To make this easier,client.auth()
stashespassword
and will send it after each connection, including reconnections.callback
is invoked only once, after the response to the very firstAUTH
command sent.
I also had to add the parameter no_ready_check: true to the call to redis.createClient().
client = redis.createClient(settings.redis.port,
settings.redis.host,
{no_ready_check: true});
if (settings.redis.password) {
client.auth(settings.redis.password, function() {
console.log('Redis client connected');
});
}
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