13

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.

1
  • 5
    You shouldn't be posting your real REDIS URL around the web. Unless you don't care about the privacy of the data inside of course. Commented Jan 28, 2014 at 9:47

2 Answers 2

20

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 to 6379 and host defaults to 127.0.0.1. If you have redis-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 to hiredis if that module is installed. This may also be set to javascript.
  • return_buffers: defaults to false. If set to true, then bulk data replies will be returned as node Buffer objects instead of JavaScript Strings.

createClient() returns a RedisClient object that is named client 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() stashes password and will send it after each connection, including reconnections. callback is invoked only once, after the response to the very first AUTH command sent.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much! The huge trip up for me was I didn't realize that long chain was the password (rather, I tried inserting my accounts password!). My final code looks liked this: var redis = require('redis'), client = redis.creatClient(9393, "icefish.redistogo.com"); client.auth("9efv34fcfdfdfdf", function() {console.log("Connected!");});
10

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');
  });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.