9

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
6
  • 1
    What you get for following command ? ./redis-cli -p 6380, assumed that you are in redis/src directory. Commented Nov 5, 2013 at 12:07
  • I get the client console where I can run my redis commands. Commented Nov 5, 2013 at 12:30
  • 3
    Try using 127.0.0.1 instead of localhost in your call to redis.createClient(). Commented Nov 6, 2013 at 17:32
  • Using 'localhost' also works for me, the problem is occasionally I get the connection exception. However, I'll replace 'localhost' with '127.0.0.1' and monitor logs to check if I get the same exception again. Thanks! Commented Nov 7, 2013 at 6:52
  • I'm facing the same issue (node "redis" module), while python "redis" module it works on the same redis instance. The Redis Cache is on MS Azure. Commented Jun 24, 2015 at 8:41

1 Answer 1

7

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");
});
Sign up to request clarification or add additional context in comments.

5 Comments

I have configured the redis instance to run on 6380 port. I want to know why / what makes the redis server stop.
Perhaps you're issuing a query that causes it to crash?
Also try handling "ready" state for redisClient. client.on("ready",function(res){}). What are you getting for above error and ready states,? print it on console.
Also check parameters to createClient() function, first is port and then it is server name.
Following the right format, var redis = require('redis'), client = redis.createClient(6380, 'localhost');. Just FYI, am using node redis module listed here. Also, I'm handling states (error, ready, connect).

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.