$ redis-cli -h ec2-75-101-204-XXX.compute-1.amazonaws.com
Could not connect to Redis at ec2-75-101-204-XXX.compute-1.amazonaws.com:6379: Operation timed out
That's what I get from my host machine. I set up the Security Group on that machine to be open to port 6379.
When I run netstat on the redis server, I see that it's listening:
$ netstat -nlp
(No info could be read for "-p": geteuid()=1000 but you should be root.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
udp 0 0 0.0.0.0:68 0.0.0.0:* -
Active UNIX domain sockets (only servers)
My redis.conf
looks like:
daemonize yes
pidfile /var/run/redis.pid
port 6379
timeout 300
loglevel notice
logfile /var/log/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
So why would I be timing out from another machine?
Redis client uses a single TCP connection and can only read one response at a time. Even when a first operation times out, it does not stop the data being sent to/from the server. Because of this, it blocks other requests and causes timeouts.
Anytime, when client application doesn't receive response before one of the timeout values expire, a timeout will occur and will be logged on client application logs as Redis timeout error message.
Continuously opening connections without closing is not a good practice. This will not only consume your resources but may also lead to program crash. The maximum number of file descriptors that you can open simultaneously is 1024.
If you want to test redis connection once at startup, use the ping() command. The command ping() checks the connection and if invalid will raise an exception. Note - the connection may still fail after you perform the test so this is not going to cover up later timeout exceptions.
redis is only listening on the localhost port: 127.0.0.1:6379
.
You need to configure redis to bind on 0.0.0.0
.
in redis.conf (most likely at /etc/redis/redis.conf
, replace (or add if not present)
bind 127.0.0.1
with
bind 0.0.0.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With