Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Asked Answered
E

21

190

I working with node.js by expressjs
I try to store an account to session. So, i try to test to use session with code in expressjs

var RedisStore = require('connect-redis')(express);
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));

but I got error Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED.
Please help me resolve this problem

Eason answered 6/1, 2012 at 6:40 Comment(4)
Is Redis running? Can you connect to it by other means e.g. redis-cli?Grope
Thank u, because redis server not running. I install redis-server follow this tutorialEason
You should instal Redis server on your machine and rune it. I donot know why the author doesn't mentioned this important thing in the manual!Superior
How do I add redis-server for my node Heroku app? I also have same error.Jointed
A
266

After you install redis, type from terminal:

redis-server

and you'll have redis running

Apomorphine answered 21/6, 2012 at 23:16 Comment(4)
For me, I should specify the conf, so I type >> (sudo) redis-server /etc/redis/redis.confAlejandroalejo
Thank you. Stupid how in the tutorial they never mentioned how to start the redis server!Originate
redis-server --daemonize yes to run in backgroundRankin
@morteza-ziyae How do I stop redis server in the background?Hartmann
P
79

I solve this problem in next way:

sudo apt-get install redis-server

then run command to confirm that everything ok:

sudo service redis-server status

And the output will be: redis-server is running - that means that the problem is solved.

Plaid answered 27/1, 2015 at 6:16 Comment(2)
that error fixed but now new error show i.e, "Error: ERR wrong number of arguments for 'set' command"Mctyre
Thanks! this resolved the issue, just a small note on Linux/WSL environments after installing re-run the command redis-server or prefix it by sudo if needed. If all goes well, you will see redis-server cli message. also can be verified by sudo service redis-server status as suggested by @author.Ogham
D
52

Install redis on your system first -

brew install redis

then start the redis server -

redis-server
Dynode answered 3/8, 2016 at 5:40 Comment(1)
brew services start redis is betterPalatine
S
23

I'm on windows, and had to install Redis from here and then run redis-server.exe.

From the top of this SO question.

Spontaneous answered 4/2, 2015 at 2:36 Comment(0)
P
21

For those of you who are using docker with docker-compose and Typescript my solution was

import { RedisClient } from 'redis';

 const pubClient = new RedisClient({ url: 'redis://redis:6379' });

to

import { createClient } from 'redis';

const pubClient = createClient({ url: 'redis://redis:6379' });

docker-compose.yml

version: '3.9'

services:
  main:
    build:
      context: .
      target: development
    ports:
      - ${PORT}:${PORT}
    volumes:
      - ./src:/usr/src/app/src
      - /app/node_modules
    env_file:
      - .env
    command: npm run start:dev
    depends_on:
      - mongo
      - redis
  mongo:
    image: mongo:5.0.2-focal
    volumes:
      - mongo-data:/data/db
  mongo-express:
    image: mongo-express:0.54.0
    ports:
      - 8081:8081
    depends_on:
      - mongo
  redis:
    image: redis:6.2.5-alpine

volumes:
  mongo-data:
Purity answered 20/8, 2021 at 4:42 Comment(1)
thank you it fixed my issue, don't know why it is not taking port and host as inputPiscatory
A
15

Simple solution:

only hit below commend once and restart your server again

redis-server
Alkalosis answered 9/10, 2018 at 9:39 Comment(0)
O
6

Using Windows 10? Go here: https://learn.microsoft.com/en-us/windows/wsl/wsl2-install

Then run...

    $ wget https://github.com/antirez/redis/archive/5.0.5.tar.gz <- change this to whatever Redis version you want (https://github.com/antirez/redis/releases)
    $ tar xzf redis-5.0.5.tar.gz
    $ cd redis-5.0.5
    $ make
Orola answered 9/12, 2018 at 8:58 Comment(0)
N
5

for Windows users, you can use chocolatey to install Redis

choco install redis-64

then run server from

C:\ProgramData\chocolatey\lib\redis-64\redis-server.exe
Notary answered 8/6, 2018 at 8:27 Comment(0)
L
4

I also have the same problem, first I tried to restart redis-server by sudo service restart but the problem still remained. Then I removed redis-server by sudo apt-get purge redis-server and install it again by sudo apt-get install redis-server and then the redis was working again. It also worth to have a look at redis log which located in here /var/log/redis/redis-server.log

Lolalolande answered 15/7, 2014 at 13:32 Comment(0)
B
3

I used ubuntu 12.04 I solved that problem by installing redis-server

redis-server installation for ubuntu 12.04

some configuration will new root permission Also listed manuals for other OS

Thanks

Besides answered 29/3, 2014 at 4:41 Comment(0)
A
2

For me I had this issue on Ubuntu 18.x, but my problem was that my redis-server was running on 127.0.0.1 but I found out I needed to run it on my IP address xxx.xx.xx.xx

I went into my Ubuntu machine and did the following.

cd /etc/redis/

sudo vim redis.conf

Then I edited this part.

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).le to listen to just one or multiple selected interfaces using
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1 ::1 10.0.0.1
bind 127.0.0.1 ::1 # <<-------- change this to what your iP address is something like (bind 192.168.2.2)

Save that, and then restart redis-server.

sudo service redis-server restart or simply run redis-server

Alexi answered 28/7, 2020 at 22:57 Comment(0)
N
1

For windows platform, You must check if redis-server is running on given ip:port. you can find redis configuration at installation directory /conf/redis.conf. by default client accept 127.0.0.1:6379.

Newbill answered 21/9, 2013 at 6:14 Comment(0)
G
1

I'm on MBP , and install redis detail my problem was resolved .Fixed the Download, extract and compile Redis with:

$ wget http://download.redis.io/releases/redis-3.0.2.tar.gz

$ tar xzf redis-3.0.2.tar.gz

$ cd redis-3.0.2

$ make

The binaries that are now compiled are available in the src directory.

Run Redis with:

$ src/redis-server 
Generic answered 16/6, 2015 at 10:46 Comment(0)
N
1

I think maybe you installed redis by source code.If that you need locate to redis-source-code-path/utils and run sudo install_server.sh command. After that, make sure redis-server has been running as a service for your system sudo service redis-server status

PS: based on Debian/Ubuntu

Numbskull answered 25/4, 2016 at 7:7 Comment(0)
H
1

In case of ubuntu, the error is due to redis-server not being set up. Install the redis-server again and then check for the status.

If there is no error, then a message like this would be displayed :-

● redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2018-01-17 20:07:27 IST; 16s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 4327 (redis-server) CGroup: /system.slice/redis-server.service └─4327 /usr/bin/redis-server 127.0.0.1:6379

Herson answered 17/1, 2018 at 14:46 Comment(0)
M
1

You have to install redis server first;

You can install redis server on mac by following step -

  $ curl -O http://download.redis.io/redis-stable.tar.gz
  $ tar xzvf redis-stable.tar.gz
  $ cd redis-stable
  $ make
  $ make test
  $ sudo make install
  $ redis-server

Good luck.

Marge answered 9/9, 2018 at 6:32 Comment(1)
Be aware: This will take some time to run. If you have a dependency manager (brew or other) this will save you time.Ophthalmoscopy
E
0

Your connection to redis is failing. Try restarting your redis server, then starting up your client again by running these 3 commands:

sudo service redis-server restart
redis-server
redis-cli
Eyesight answered 20/1, 2016 at 13:34 Comment(2)
Please explain your answer. It is currently viewed as a low quality post. Thanks!Tyche
i got this error in ubuntu...solve with this commands..now it's working fine .....Eyesight
B
0

For Windows I solved this by...

using...

let redisClient = createClient({
  legacyMode: true ,
  url: 'redis://redis:6379',
});

Its for redis version > 4.0
You can refer to the image below.

1

Brezin answered 5/8, 2022 at 3:58 Comment(0)
S
0

If your project runs on windows,

  1. You must setup and run redis-server on your windows.
  2. Run 'npm i redis' in your project It will work correctly
Sturm answered 10/4, 2023 at 8:16 Comment(2)
Hi, please note, original question was 11 years ago. But, why Windows? There is no such detail in the question…Antecede
Hi, I know that original question was 11 years ago, but in my project I got this error and solved with this commands.Sturm
A
0

If you run redis in docker you must set port:

Alphonsa answered 14/2 at 17:40 Comment(0)
G
-7

Try upgrading your node to latest version.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

version 0.4 may not work properly.

Gnosticize answered 7/8, 2013 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.