Nodejs fails with redis error

I use Node.js, Express, Redis and Socket.io. When Redis does not work, Node.js terminates.

How can I prevent this, perhaps re-create the code somewhere or something else?

Output:

info - socket.io started Express server listening on port 3000 

Error:

 events.js:72 throw er; // Unhandled 'error' event ^ Error: Redis connection to 127.0.0.1:6380 failed - connect ECONNREFUSED at RedisClient.on_error (...../node_modules/redis/index.js:151:24) at Socket.<anonymous> (...../node_modules/redis/index.js:86:14) at Socket.EventEmitter.emit (events.js:95:17) at net.js:426:14 at process._tickCallback (node.js:415:13) 
+4
source share
1 answer

It looks like you don't have an error handler for your redis client instance. Can you provide some excerpt from your code? We can probably help you with this. Just the error message is a little less.

If I had to guess, I would say that you do not have an error handler ...

See here: https://github.com/mranney/node_redis#usage

Do you have an answer to the error?

Example:

 var redis = require("redis"), client = redis.createClient(); // This is required so your error doesn't bubble // upwards and kills your instance client.on("error", function (err) { console.log("Error " + err); }); 

The node_redis client automatically reconnects, so you do not need to process it, although you can configure max_attempts and other parameters. See here: https://github.com/mranney/node_redis#rediscreateclientport-host-options

Hope I could provide some useful information.

+9
source

Source: https://habr.com/ru/post/1500018/


All Articles