Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis & NodeJS - Connection exception

Tags:

node.js

redis

I'm using Redis DB with NodeJS. Occasionally I get below exception and my server (NodeJS) crashes only to restart again.

Error: Redis connection to localhost:6380 failed - getaddrinfo ENOTFOUND

Can someone explain why this happens? Does the below config has something to do with this?

# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able ot configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# maxclients 10000
like image 576
Ayaz Pasha Avatar asked Nov 05 '13 08:11

Ayaz Pasha


People also ask

What is Redis used for?

Redis enables you to write traditionally complex code with fewer, simpler lines. With Redis, you write fewer lines of code to store, access, and use data in your applications. The difference is that developers who use Redis can use a simple command structure as opposed to the query languages of traditional databases.

Is Redis a cache or database?

Redis is a database for a range of data sizes, from a few megabytes to hundreds of terabytes. With Redis Enterprise, you can use Redis as both an in-memory cache and a primary database in a single system, thus eliminating the complexity and latency of two separate systems.

Is Redis a NoSQL?

Redis is an open source, in-memory key-value data structure store, which can be used as a database, cache, or message broker. It's a NoSQL database.


1 Answers

This simply means your redis server isn't running; at least not on that address/port.

Start your server using

$ redis-server path/to/redis.conf

Also the default redis port is 6379. If you're using 6380 in your scripts, make sure redis is listening on that port.


If something in your script is causing the redis server to crash, you can try listening for errors to get some more sensible output

var redis  = require("redis"),
    client = redis.createClient(6380, "localhost");

client.on("error", function (err) {
  console.log("Redis error encountered", err);
});

client.on("end", function() {
  console.log("Redis connection closed");
});
like image 200
maček Avatar answered Oct 04 '22 05:10

maček