从redis / index.js文件中捕获连接错误throw(n)

时间:2020-12-04 23:58:49

I am connecting to redis thru heroku.

我通过heroku连接到redis。

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?

redis.index.js文件是错误的我怎么抓住它打印到控制台?

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 个解决方案

#1


0  

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.

您可能还希望稍后添加对不同形式的错误的处理。

#2


1  

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

你在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.

真正的问题是你无法连接到mongodb,这会在redis-client调用的回调函数中引发异常。

#1


0  

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.

您可能还希望稍后添加对不同形式的错误的处理。

#2


1  

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

你在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.

真正的问题是你无法连接到mongodb,这会在redis-client调用的回调函数中引发异常。