0

I am connecting to redis thru heroku.

var redisClient = require('redis').createClient({
    host: 'http://networkinglawyer.in/home/redis',
    port: 9374,
    db: 0,
    requirepass: 'abcdefghijklmnopqrstuvwxyz'
  });

The redis.index.js file is throwing err how do i catch to print it onto console?

Edit:- Error is

2013-11-29T07:18:38.255695+00:00 app[web.1]: userSchema defined
2013-11-29T07:18:38.262109+00:00 app[web.1]: questionSchema defined
2013-11-29T07:18:38.264414+00:00 app[web.1]: activitySchema defined
2013-11-29T07:18:38.273814+00:00 app[web.1]: connection error: [Error: failed to connect to [localhost:27017]]
2013-11-29T07:18:38.282107+00:00 app[web.1]: 
2013-11-29T07:18:38.282867+00:00 app[web.1]:                 throw callback_err;
2013-11-29T07:18:38.282528+00:00 app[web.1]: /app/node_modules/redis/index.js:563
2013-11-29T07:18:38.283575+00:00 app[web.1]:                       ^
2013-11-29T07:18:38.287475+00:00 app[web.1]:     at RedisClient.on_info_cmd (/app/node_modules/redis/index.js:371:35)
2013-1
2
  • Tell more about what you can see. Commented Nov 29, 2013 at 9:50
  • @hgoebl put up the error in Edit; Commented Nov 29, 2013 at 10:31

2 Answers 2

1

To catch the error and print it to the console:

redisClient.on('error', function (err) {
    console.log('Error ' + err);
});

You may also want to add handling of different forms of errors in later as well.

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

1 Comment

Yes, it is an excellent idea to place an error-handler for redisClient. In this case redisClient doesn't emit an error but only throws one due to unsufficient error handling of a callback function.
1

You have an error in a callback-function which is called by redis:

// from https://github.com/mranney/node_redis/blob/master/index.js
if (command_obj && typeof command_obj.callback === "function") {
    try {
        command_obj.callback(err);
    } catch (callback_err) {
        // if a callback throws an exception, re-throw it on a new stack so the parser can keep going
        process.nextTick(function () {
            throw callback_err;
        });
    }
}

The real problem is that you cannot connect to mongodb and this throws an exception in a callback function invoked by redis-client.

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.