3

I tried install redis client in system and run node js code its working fine. but I tried to redis client configure to set host and port in node js.but its not connected its throwing connection refused error.how to resolve it any one give suggestion.

cache.js

//Import redis
const redis = require('redis');

const { promisify } = require('util');

const host = "127.0.0.1"

const port = 6379

//Connecting redis client
const client = redis.createClient(port,host,redis)

client.on('connect', function () {
    console.log("Redis Connected")
});

client.on('error', function (err) {
    console.log(err)
});

{ Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 at Object._errnoException (util.js:1022:11) at _exceptionWithHostPort (util.js:1044:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14) code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 6379 }

2
  • Please check whether the REDIS is running in your local system. Commented May 30, 2019 at 4:36
  • 1
    Thank you its working fine Commented May 30, 2019 at 5:03

1 Answer 1

0

The code for connecting to redis seems to work fine. You can check if redis is running on your system:

sudo service redis status

If the status is not active try to restart the service. You can refer to this code for creating a better wrapper for redis: https://github.com/kumaranshu72/node_ts_boilerplate/blob/github/src/utils/redis.ts

Sign up to request clarification or add additional context in comments.

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.