0

I am trying to use redis using this segment of code:

const redis = require('redis');
const client = redis.createClient();

I am getting the following error:

events.js:174
  throw er; // Unhandled 'error' event
  ^

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
4
  • Is redis running on your system? Commented Apr 4, 2019 at 0:36
  • I added with: npm i --save redis Commented Apr 4, 2019 at 0:37
  • You need to run a redis server on your machine to be able to connect to it from javascript. Commented Apr 4, 2019 at 0:38
  • I did redis-server but the command is not recognized. What am I supposed to do? Commented Apr 4, 2019 at 0:38

1 Answer 1

1

You will need to first install redis on your system. To do so, follow the instructions here.

Then run the following command in your command prompt/terminal:

redis-server

If you want to run redis in the background without having to start it everytime, then you can use:

redis-server --daemonize yes

You can check if your server is running by using the command:

redis-cli set a 3 & redis-cli get a

If this works then your redis server has started successfully. After this, your previous code should be able to connect to the redis-server provided the server is running on the default port (6379).

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

2 Comments

what OS are you using? Have you installed redis successfully? Maybe it is just a matter of adding the redis-path in your .bashrc/PATH variable
That seems to work. I had downloaded redis using npm but it has to be downloaded as a Window service using msi. If you would like to write out your answer I will be glad to check it. There are tons of the same question on StackOverflow with no correct answer.

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.