0

I use 'redis' module in my app. But it's throw error. My code is following -

//app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var redis = require('redis');

var client = redis.createClient('localhost', 3000); 
client.on('connect', function() {
    console.log("connected");
});

Here is the error:

Adityas-MacBook-Air:node_elastic_redis adityagupta$ npm start 

> [email protected] start /Users/adityagupta/Desktop/node_elastic_redis 
> node ./bin/www events.js:154 throw er; // Unhandled 'error' event ^ 

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 
    at Object.exports._errnoException (util.js:856:11) 
    at exports._exceptionWithHostPort (util.js:879:20) 
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1057:14)
3
  • Redis usually installs itself on port 6379, why are you using 3000? Commented Mar 8, 2016 at 19:22
  • Adityas-MacBook-Air:node_elastic_redis adityagupta$ npm start > [email protected] start /Users/adityagupta/Desktop/node_elastic_redis > node ./bin/www events.js:154 throw er; // Unhandled 'error' event ^ Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 at Object.exports._errnoException (util.js:856:11) at exports._exceptionWithHostPort (util.js:879:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1057:14) Commented Mar 8, 2016 at 19:27
  • my node application using 3000. Commented Mar 8, 2016 at 19:30

3 Answers 3

2

The port should be the first argument according to documentation like so:

redis.createClient(port[, host][, options])

Or in your case:

var client = redis.createClient(6379, 'localhost');
Sign up to request clarification or add additional context in comments.

Comments

1

Based on the error message, either redis is not running, or not running on the port specified.

Try using the default redis port of 6379. If you are running redis on the same machine the node app is running on, you may not have to specify the host and port:

var client = redis.createClient('localhost', 6379);

or

var client = redis.createClient();

1 Comment

By using redis.createClient('localhost', 6379); It's generate - /Users/adityagupta/Desktop/node_elastic_redis/node_modules/redis/index.js:1303 options.path = port_arg;
0

You only installed a driver without the actual server , For redis to work ... you have to install redis server on your local machine.

Head to Redis Official Site to get the latest version of redis , if you are using windows by any chance , Have a look at these

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.