使用自制程序安装Redis,但当我尝试ping Redis时,它显示这个错误:

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

注意: 我尝试关闭防火墙并编辑conf文件,但仍然无法ping通。 我使用的是macOS Sierra和自制版本1.1.11


当前回答

就像Aaron一样,在我的案例中,brew services list声称redis正在运行,但实际上并没有。我在/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

这是由以下配置引起的:

bind 127.0.0.1 ::1 192.168.161.1

这是让我的VMWare Fusion虚拟机访问macOS主机上的redis服务器所必需的。但是,如果虚拟机没有启动,这个绑定失败会导致redis根本不启动。所以启动虚拟机就解决了这个问题。

其他回答

我在这件事上耽搁了很长时间。经过多次尝试,我终于能够正确地配置它了。

产生误差的原因有很多。我试图提供原因和解决方案,以克服这种情况。确保正确安装了redis-server。

6379 Port is not allowed by ufw firewall. Solution: type following command sudo ufw allow 6379 The issue can be related to permission of redis user. May be redis user doesn't have permission of modifying necessary redis directories. The redis user should have permissions in the following directories: /var/lib/redis /var/log/redis /run/redis /etc/redis To give the owner permission to redis user, type the following commands: sudo chown -R redis:redis /var/lib/redis sudo chown -R redis:redis /var/log/redis sudo chown -R redis:redis /run/redis sudo chown -R redis:redis /etc/redis. Now restart redis-server by following command: sudo systemctl restart redis-server

希望这对某些人有所帮助。

在自制MacOS上有这个问题吗?问题是/usr/local/var/log目录上缺少某种权限,见这里的问题

为了解决这个问题,我删除了/usr/local/var/log并重新安装redis

redis-server --daemonize yes

通过运行该命令解决了此问题。

Mac版Redis:

1-酿造安装redis 2-酿造服务启动redis 3- redis-cli ping

$ brew services start redis 
$ brew services stop redis
$ brew services restart redis

午餐自动启动选项:

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
# autostart activate
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
# autostart deactivate
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

Redis conf默认路径:/usr/local/etc/redis.conf

我刚刚遇到了同样的问题,因为我在配置文件中使用了不正确的语法。我想补充一点:

maxmemory-policy allkeys-lru

到我的配置文件中,但只添加了:

allkeys-lru

这显然阻止了Redis解析配置文件,这反过来又阻止了我通过cli连接。修正这个语法可以让我连接到Redis。