Could not connect to Redis at 127.0.0.1:6379: Connection refused with homebrew
Using homebrew to install Redis but when I try to ping Redis it shows this error:
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Note : I tried to turn off firewall and edit conf file but still cannot ping. I am using macOS Sierra and homebrew version 1.1.11
Solution 1:
After installing redis
, type from terminal
:
redis-server
And Redis-Server will be started
Solution 2:
I found this question while trying to figure out why I could not connect to redis after starting it via brew services start redis
.
tl;dr
Depending on how fresh your machine or install is you're likely missing a config file or a directory for the redis defaults.
-
You need a config file at
/usr/local/etc/redis.conf
. Without this fileredis-server
will not start. You can copy over the default config file and modify it from there withcp /usr/local/etc/redis.conf.default /usr/local/etc/redis.conf
-
You need
/usr/local/var/db/redis/
to exist. You can do this easily withmkdir -p /usr/local/var/db/redis
Finally just restart redis with brew services restart redis
.
How do you find this out!?
I wasted a lot of time trying to figure out if redis wasn't using the defaults through homebrew and what port it was on. Services was misleading because even though redis-server
had not actually started, brew services list
would still show redis as "started." The best approach is to use brew services --verbose start redis
which will show you that the log file is at /usr/local/var/log/redis.log
. Looking in there I found the smoking gun(s)
Fatal error, can't open config file '/usr/local/etc/redis.conf'
or
Can't chdir to '/usr/local/var/db/redis/': No such file or directory
Thankfully the log made the solution above obvious.
Can't I just run redis-server
?
You sure can. It'll just take up a terminal or interrupt your terminal occasionally if you run redis-server &
. Also it will put dump.rdb
in whatever directory you run it in (pwd
). I got annoyed having to remove the file or ignore it in git so I figured I'd let brew do the work with services.