Php – “Connection Refused” error on Redis

“Connection Refused” error on Redis… here is a solution to the problem.

“Connection Refused” error on Redis

I have a running Redis instance (v2.8) on our LAN that is running and accessible via LAN IP and localhost. The problem is that we get random “connection refused” errors from the client. They succeed many times, but failures happen often.

And there are no errors in Redis. It doesn’t report any rejected connections, so I’m inclined to believe it’s something in Linux. Looking at the INFO output is as follows:

info
# Server
redis_version:2.8.0
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:8c972dc122b48b0
redis_mode:standalone
os:Linux 3.2.0-56-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.6.3
process_id:32455
run_id:c2536f78b7277e44bb03d1872bb0ede6764bd719
tcp_port:6379
uptime_in_seconds:531319
uptime_in_days:6
hz:10
lru_clock:204248
config_file:/etc/redis/redis.conf

# Clients
connected_clients:11
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:20166048208
used_memory_human:18.78G
used_memory_rss:20565544960
used_memory_peak:20171368288
used_memory_peak_human:18.79G
used_memory_lua:33792
mem_fragmentation_ratio:1.02
mem_allocator:jemalloc-3.4.1

# Persistence
loading:0
rdb_changes_since_last_save:548
rdb_bgsave_in_progress:0
rdb_last_save_time:1386162582
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:142
rdb_current_bgsave_time_sec:-1
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:104
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_current_size:10938614211
aof_base_size:5791948107
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:4616

# Stats
total_connections_received:1024359
total_commands_processed:500283574
instantaneous_ops_per_sec:88
rejected_connections:0
sync_full:1
sync_partial_ok:5
sync_partial_err:0
expired_keys:79
evicted_keys:0
keyspace_hits:225004198
keyspace_misses:17265265
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:294076

# Replication
role:master
connected_slaves:1
slave0:ip=192.168.0.203,port=6379,state=online,offset=13777559286,lag=1
master_repl_offset:13777559286
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:13776510711
repl_backlog_histlen:1048576

# CPU
used_cpu_sys:4233.39
used_cpu_user:5293.61
used_cpu_sys_children:5679.02
used_cpu_user_children:115598.34

# Keyspace
db0:keys=73514342,expires=10,avg_ttl=39196243

I’m only seeing about 50 concurrent connections, with occasional bursts, so I don’t think I’m hitting any file descriptor limits. I’ve increased the soft limit to 90,000 descriptors. The sysctl fs.file-max setting is also high.

sysctl fs.file-max
fs.file-max = 1622320

Our 100Mb/s LAN line is not saturated. So what’s the problem? We keep getting tickets from users saying “Connection refused” errors.

Solution

I have a very similar question. The problem for me is that my Redis instance only listens on IPv4 addresses, but my HostName (localhost in my case) application connects to resolve to IPv4 and IPv6 addresses. As long as the application uses an IPv4 address, it works. However, when it uses the ipv6 address, it gives a Connection refused error.

To resolve this issue, configure Redis to listen on both IPv4 and IPv6 addresses, or configure your application to use IPv4 addresses instead of host names.

Related Problems and Solutions