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
O. Jones
99.3k17 gold badges118 silver badges165 bronze badges
asked Jan 6, 2012 at 6:40
4
After you install redis, type from terminal:
redis-server
and you’ll have redis running
answered Jun 21, 2012 at 23:16
![]()
piggybackpiggyback
8,92413 gold badges50 silver badges80 bronze badges
4
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.
Loolooii
8,41314 gold badges64 silver badges90 bronze badges
answered Jan 27, 2015 at 6:16
cn007bcn007b
16.3k7 gold badges58 silver badges73 bronze badges
2
Install redis on your system first —
brew install redis
then start the redis server —
redis-server
answered Aug 3, 2016 at 5:40
![]()
Partha RoyPartha Roy
1,56515 silver badges16 bronze badges
1
I’m on windows, and had to install Redis from here and then run redis-server.exe.
From the top of this SO question.
answered Feb 4, 2015 at 2:36
FelixFelix
3,5755 gold badges33 silver badges50 bronze badges
0
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:
answered Aug 20, 2021 at 4:42
goodoniongoodonion
1,12111 silver badges22 bronze badges
1
Simple solution:
only hit below commend once and restart your server again
redis-server
answered Oct 9, 2018 at 9:39
![]()
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
answered Dec 9, 2018 at 8:58
buycanna.iobuycanna.io
1,15616 silver badges18 bronze badges
for Windows users, you can use chocolatey to install Redis
choco install redis-64
then run server from
C:ProgramDatachocolateylibredis-64redis-server.exe
answered Jun 8, 2018 at 8:27
![]()
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
answered Jul 15, 2014 at 13:32
![]()
SadeghSadegh
2,6291 gold badge22 silver badges26 bronze badges
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
answered Mar 29, 2014 at 4:41
![]()
0
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
answered Jul 28, 2020 at 22:57
![]()
haron68haron68
7311 gold badge4 silver badges18 bronze badges
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.
answered Sep 21, 2013 at 6:14
A GuptaA Gupta
5,45810 gold badges51 silver badges88 bronze badges
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
Stewartside
19.9k12 gold badges63 silver badges80 bronze badges
answered Jun 16, 2015 at 10:46
0
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
answered Apr 25, 2016 at 7:07
sudozsudoz
3,0951 gold badge21 silver badges19 bronze badges
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
answered Jan 17, 2018 at 14:46
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.
Dev
1,5061 gold badge20 silver badges42 bronze badges
answered Sep 9, 2018 at 6:32
1
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
Barett
5,6866 gold badges49 silver badges55 bronze badges
answered Jan 20, 2016 at 13:34
2
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.

vimuth
4,60123 gold badges72 silver badges112 bronze badges
answered Aug 5, 2022 at 3:58
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.
rzymek
8,9132 gold badges45 silver badges59 bronze badges
answered Aug 7, 2013 at 8:38
![]()
Vaisakh VMVaisakh VM
1,05111 silver badges9 bronze badges
0

Most webmasters and web hosts that use Redis would have seen this error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
It is usually caused when the Redis service is stopped in the server.
As part of our Server Management Services for online service providers and website owners, we have seen several other causes for this error.
Today we’ll go through the top causes and fixes for the Redis connection refused error.
What causes Redis connection refused error?
Redis is used by many to reduce application load time. However, users at times complain that they receive a connection refused error after installing the Redis extension.
The common reasons that trigger the error include:
- Redis-Server not Started
- Firewall Restriction
- Resource usage
Apart from these, there are some alternate reasons that trigger the Redis connection error. Today, let’s look into the reasons for could not connect to Redis connection refused error and its fixes.
Redis-Server is not started
The most common reason for the connection refused error is that the Redis-Server is not started.
Redis server should be started to use the Redis client after its installation. It can be done with the following command.
redis-server
Also to run Redis in the background, following command could be used.
redis-server --daemonize yes
Firewall restriction
Firewall restriction is another common reason that can trigger the “could not connect to Redis connection refused”.
By default Redis server listen to the TCP port 6379. If another application is using the port or if the firewall restrictions blocks the port, it can trigger the connection refused error.
Thus it is important to check the status of the port in the firewall configuration while troubleshooting the could not connect to Redis error.
Resource usage
As we discussed earlier, Redis uses the main memory to store the data. Thus if the resource in the server is not sufficient for the process to run, it may get terminated abruptly.
When the status of the Redis process is down, it triggers the could not connect to Redis error. We could confirm if it actually running using the ps command.
ps -aux | grep redis
Our Support Engineers analyzes the Redis log file to confirm if the service is repeatedly flapping in the server. From a simultaneous analysis of other log files, we confirm if any other process is consuming resources in the server and is causing Redis to terminate.
Alternate reasons
Apart from the reasons mentioned above some settings in the Redis configuration file could also result in the connection failed error. The default location for the configuration file in Ubuntu 18 is /etc/redis/redis.conf.
Some of the reasons that may trigger the connection refused error include:
- The password set in the Redis configuration file. To fix it, comment the following line.
#requirepass <some pass if any>
- If the IP binding is not open for access from the internet in the config. Commenting the following lines will fix the issue.
# bind 127.0.0.1 ::1
[Are you struggling with Redis errors? We’ll fix it right away.]
Conclusion
In short, a number of reasons can trigger the Redis connection refused error. This ranges from firewall restrictions to resource limitations. Today we discussed how our Support Engineers fixes the error in each scenario.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
GET STARTED
var google_conversion_label = «owonCMyG5nEQ0aD71QM»;
I am on osx and I’m trying to use this container by doing:
$ docker run --name redis -p 6379:6379 -d redis
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1af8a2abcae9 redis "/entrypoint.sh redis" 3 minutes ago Up 3 minutes 0.0.0.0:6379->6379/tcp redis
Based on this it seems like the container is running properly, and the key being: 0.0.0.0:6379->6379/tcp
However when I attempt to connect to the server via node_redis with code like this:
var redis = require('redis');
var client = redis.createClient(); // localhost:6379
client.on('error', function (err) {
console.log('Redis Error:', err); // errors here
});
I get this error:
Redis Error: { [Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379 }
I’ve tried using some other clients, and they all do the same thing. Furthermore, trying to use the linking suggested in the documentation here, this same code when run in that container is also having this error.
What am I missing?
Overview
This topic describes why Redis connection problems occur and how to solve the problems.
Problem Classification
To troubleshoot abnormal connections to a Redis instance, check the following items:
- Connection Between the Redis Instance and the ECS
- Public Access (Redis 3.0 Only)
- Password
- Instance Configuration
- Client Connections
- Bandwidth
- Redis Performance
Connection Between the Redis Instance and the ECS
The ECS where the client is located must be in the same VPC as the Redis instance and be able to communicate with the Redis instance.
- For a Redis 3.0 instance, check the security group rules of the instance and the ECS.
Correctly configure security group rules for the ECS and the Redis instance to allow the Redis instance to be accessed. For details, see How Do I Configure a Security Group?
- For a DCS Redis 4.0 or 5.0 instance, check the whitelist of the instance.
If the instance has a whitelist, ensure that the client IP address is included in the whitelist. Otherwise, the connection will fail. For details, see Managing IP Address Whitelist. If the client IP address changes, add the new IP address to the whitelist.
- Check the regions of the Redis instance and the ECS.
If the Redis instance and the ECS are not in the same region, create another Redis instance in the same region as the ECS and migrate data from the old instance to the new instance by referring to Data Migration Guide.
- Check the VPCs of the Redis instance and the ECS.
Different VPCs cannot communicate with each other. An ECS cannot access a Redis instance if they are in different VPCs. You can establish VPC peering connections to allow the ECS to access the Redis instance across VPCs.
For more information on how to create and use VPC peering connections, see VPC Peering Connection.
Public Access (Redis 3.0 Only)
Before accessing a Redis instance through a public network, ensure that the instance supports public access. For details, see the public access explanation.
- Symptom: «Error: Connection reset by peer» is displayed or a message is displayed indicating that the remote host forcibly closes an existing connection.
- Possible cause 1: The security group is incorrectly configured.
Solution: Correctly configure the Redis instance and access the instance by following the public access instructions.
- Possible cause 2: Check whether the VPC subnet where Redis resides is associated with a network ACL and whether the network ACL denies outbound traffic. If yes, remove the ACL restriction.
- Possible cause 3: SSL encryption has been enabled, but Stunnel is not configured during connection. Instead, the IP address displayed on the console was used for connection.
Solution: When enabling SSL encryption, install and configure the Stunnel client. For details, see Enabling SSL Encryption. In the command for connecting to the Redis instance, the address must be set to the IP address and port number of the Stunnel client. Do not use the public access address and port displayed on the console.
- Possible cause 1: The security group is incorrectly configured.
- Symptom: Public access has been automatically disabled.
Cause: The EIP bound to the DCS Redis instance is unbound. As a result, public access is automatically disabled.
Solution: Enable public access for the instance and bind an EIP to the instance on the management console. Then, try again.
Password
If the instance password is incorrect, the port can still be accessed but the authentication will fail. If you forget the password, you can reset the password. For details, see Resetting Instance Passwords.
Instance Configuration
If a connection to Redis is rejected, log in to the DCS console, go to the instance details page, and modify the maxclients parameter. For details, see Modifying Configuration Parameters.
Client Connections
- The connection fails when you use redis-cli to connect to a Redis Cluster instance.
Solution: Check whether -c is added to the connection command. Ensure that the correct connection command is used when connecting to the cluster nodes.
- Run the following command to connect to a Redis Cluster instance:
./redis-cli -h {dcs_instance_address} -p 6379 -a {password} -c
- Run the following command to connect to a single-node, master/standby, or Proxy Cluster instance:
./redis-cli -h {dcs_instance_address} -p 6379 -a {password}
For details, see Access Using redis-cli.
- Run the following command to connect to a Redis Cluster instance:
- Error «Read timed out» or «Could not get a resource from the pool» occurs.
Solution:
- Check if the KEYS command has been used. This command consumes a lot of resources and can easily block Redis. Instead, use the SCAN command and do not execute the command frequently.
- Check if the DCS instance is Redis 3.0. Redis 3.0 uses SATA disks. During AOF persistence, the disk performance may occasionally deteriorate and cause a connection failure. In this case, disable AOF persistence if data persistence is not required. Alternatively, you can use a DCS Redis 4.0 instance or later because they use SSD disks that offer higher performance.
- Error «unexpected end of stream» occurs and causes service exceptions.
Solution:
- Optimize the Jedis connection pool by referring to Recommended Jedis Parameter Settings.
- Check whether there are many big keys. For details, see How Do I Avoid Big Keys and Hot Keys?
- The connection is interrupted.
Solution:
- Modify the application timeout duration.
- Optimize the service to avoid slow queries.
- Replace the KEYS command with the SCAN command.
- If an error occurs when you use the Jedis connection pool, see Troubleshooting a Jedis Connection Pool Error.
Bandwidth
If the bandwidth reaches the upper limit of the corresponding instance specifications, Redis connections may time out.
You can view the Flow Control Times metric to check whether the bandwidth has reached the upper limit.
Then, check whether the instance has big keys and hot keys. If a single key is too large or overloaded, operations on the key may occupy too many bandwidth resources. For details about big keys and hot keys, see Analyzing Big Keys and Hot Keys.
Redis Performance
Connections to an instance may become slow or time out if the CPU usage spikes due to resource-consuming commands such as KEYS, or too much memory is used because the expiration time is not set for the instance or expired keys remain in the memory. In these cases, do as follows:
- Use the SCAN command instead of the KEYS command, or disable the KEYS command.
- Check the monitoring data and configure alarm rules. For details, see Setting Alarm Rules for Critical Metrics.
For example, you can view the Memory Usage and Used Memory metrics to keep track of the instance memory usage, and view the Connected Clients metric to determine whether the instance connections limit has been reached.
- Check whether the instance has big keys and hot keys.
For details about the operations of big key and hot key analysis, see Analyzing Big Keys and Hot Keys.
У меня была эта проблема на Ubuntu 18.x, но моя проблема заключалась в том, что мой redis-сервер работал на 127.0.0.1, но я обнаружил, что мне нужно запустить его на моем IP-адресе xxx.xx.xx.xx
Я зашел в свою машину с Ubuntu и сделал следующее.
cd /etc/redis/
sudo vim redis.conf
Потом я отредактировал эту часть.
################################## 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)
Сохраните это, а затем перезапустите redis-server.
sudo service redis-server restart или просто беги redis-server