Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED

Javascriptnode.jsExpressRedisEconnrefused

Javascript Problem Overview


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

Javascript Solutions


Solution 1 - Javascript

After you install redis, type from terminal:

redis-server

and you'll have redis running

Solution 2 - Javascript

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.

Solution 3 - Javascript

Install redis on your system first -

brew install redis

then start the redis server -

redis-server

Solution 4 - Javascript

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

From the top of this SO question.

Solution 5 - Javascript

> Simple solution:

only hit below commend once and restart your server again

redis-server

Solution 6 - Javascript

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:

Solution 7 - Javascript

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

Solution 8 - Javascript

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

Solution 9 - Javascript

Using Windows 10? Go here: https://docs.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

Solution 10 - Javascript

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

Solution 11 - Javascript

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.

Solution 12 - Javascript

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 

Solution 13 - Javascript

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

Solution 14 - Javascript

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

Solution 15 - Javascript

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.

Solution 16 - Javascript

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

Solution 17 - Javascript

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

Solution 18 - Javascript

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHuy TranView Question on Stackoverflow
Solution 1 - JavascriptpiggybackView Answer on Stackoverflow
Solution 2 - Javascriptcn007bView Answer on Stackoverflow
Solution 3 - JavascriptPartha RoyView Answer on Stackoverflow
Solution 4 - JavascriptFelixView Answer on Stackoverflow
Solution 5 - JavascriptShashwat GuptaView Answer on Stackoverflow
Solution 6 - JavascriptgoodonionView Answer on Stackoverflow
Solution 7 - JavascriptBarış Serkan AKINView Answer on Stackoverflow
Solution 8 - JavascriptSadeghView Answer on Stackoverflow
Solution 9 - Javascriptbuycanna.ioView Answer on Stackoverflow
Solution 10 - JavascriptPaing Soe ThawView Answer on Stackoverflow
Solution 11 - JavascriptA GuptaView Answer on Stackoverflow
Solution 12 - JavascriptHalilertekinView Answer on Stackoverflow
Solution 13 - JavascriptsudozView Answer on Stackoverflow
Solution 14 - JavascriptYadnesh SawantView Answer on Stackoverflow
Solution 15 - JavascriptSaiful Islam SajibView Answer on Stackoverflow
Solution 16 - Javascriptharon68View Answer on Stackoverflow
Solution 17 - JavascriptBalakumaranView Answer on Stackoverflow
Solution 18 - JavascriptVaisakh VMView Answer on Stackoverflow