Could not connect to Redis at 127.0.0.1:6379: Connection refused with homebrew

前端 未结 12 1490
灰色年华
灰色年华 2020-12-22 22:10

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

相关标签:
12条回答
  • 2020-12-22 22:49

    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.

    1. 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
      
    2. 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.

    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.

    0 讨论(0)
  • 2020-12-22 22:49

    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.

    0 讨论(0)
  • 2020-12-22 22:54

    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

    0 讨论(0)
  • 2020-12-22 22:56

    Try this :

    sudo service redis-server restart
    
    0 讨论(0)
  • 2020-12-22 23:00

    In my case, it was the password that contained some characters like ', after changing it the server started without problems.

    0 讨论(0)
  • 2020-12-22 23:01

    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.

    0 讨论(0)
提交回复
热议问题