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
I found this question while trying to figure out why I could not connect to redis after starting it via brew services start redis
.
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 file redis-server
will not start. You can copy over the default config file and modify it from there with
cp /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 with
mkdir -p /usr/local/var/db/redis
Finally just restart redis with brew services restart redis
.
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.
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.
I just had this same problem because I had used improper syntax in my config file. I meant to add:
maxmemory-policy allkeys-lru
to my config file, but instead only added:
allkeys-lru
which evidently prevented Redis from parsing the config file, which in turn prevented me from connecting through the cli. Fixing this syntax allowed me to connect to Redis.
Had that issue with homebrew MacOS
the problem was some sort of permission missing on /usr/local/var/log
directory see issue here
In order to solve it I deleted the /usr/local/var/log
and reinstall redis brew reinstall redis
Try this :
sudo service redis-server restart
In my case, it was the password that contained some characters like '
, after changing it the server started without problems.
Just like Aaron, in my case brew services list
claimed redis was running, but it wasn't. I found the following information in my log file at /usr/local/var/log/redis.log
:
4469:C 28 Feb 09:03:56.197 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4469:C 28 Feb 09:03:56.197 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=4469, just started
4469:C 28 Feb 09:03:56.197 # Configuration loaded
4469:M 28 Feb 09:03:56.198 * Increased maximum number of open files to 10032 (it was originally set to 256).
4469:M 28 Feb 09:03:56.199 # Creating Server TCP listening socket 192.168.161.1:6379: bind: Can't assign requested address
That turns out to be caused by the following configuration:
bind 127.0.0.1 ::1 192.168.161.1
which was necessary to give my VMWare Fusion virtual machine access to the redis server on macOS, the host. However, if the virtual machine wasn't started, this binding failure caused redis not to start up at all. So starting the virtual machine solved the problem.