在 macOS 上安装 Redis Stack
如何在 macOS 上安装 Redis Stack
要在 macOS 上安装 Redis Stack,请使用 Homebrew。在开始以下安装说明之前,请确保您已 安装 Homebrew。
有三个可用的 brew casks。
redis-stack
包含redis-stack-server
和redis-stack-redisinsight
两部分。redis-stack-server
仅提供 Redis Stack 服务器。redis-stack-redisinsight
包含 Redis Insight。
使用 Homebrew 安装
首先,添加 Redis Stack Homebrew 仓库
brew tap redis-stack/redis-stack
接下来,运行 brew install
brew install redis-stack
redis-stack-server
将安装所有 Redis 和 Redis Stack 二进制文件。如何运行这些二进制文件取决于你的系统是否已经安装了 Redis。
首次安装 Redis
如果这是你第一次在系统上安装 Redis,你需要确保你的 PATH
变量包含 Redis Stack 的安装路径。该路径是 Apple 芯片 Mac 的 /opt/homebrew/bin
或 Intel Mac 的 /usr/local/bin
。
要检查这一点,请运行
echo $PATH
然后,确认输出中包含 /opt/homebrew/bin
(Apple 芯片 Mac)或 /usr/local/bin
(Intel Mac)。如果这些目录不在输出中,请参见下面的“现有 Redis 安装”说明。
brew tap
命令安装的,因此它不会与 brew services
命令集成。现有 Redis 安装
如果你在系统上有一个现有的 Redis 安装,你可能需要修改你的 $PATH
来确保你使用的是最新的 Redis Stack 二进制文件。
打开文件 ~/.bashrc
或 ~/zshrc
(取决于你的 shell),并添加以下行。
对于 Intel Mac
export PATH=/usr/local/Caskroom/redis-stack-server/<VERSION>/bin:$PATH
对于 Apple 芯片 Mac
export PATH=/opt/homebrew/Caskroom/redis-stack-server/<VERSION>/bin:$PATH
在这两种情况下,请将 <VERSION>
替换为你自己的 Redis Stack 版本。例如,对于版本 6.2.0,路径如下
export PATH=/opt/homebrew/Caskroom/redis-stack-server/6.2.0/bin:$PATH
启动 Redis Stack Server
现在你可以按如下方式启动 Redis Stack Server
redis-stack-server
安装 Redis Stack 后安装 Redis
如果你已经使用 Homebrew 安装了 Redis Stack,然后尝试使用 brew install redis
安装 Redis,你可能会遇到以下错误
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/redis-benchmark
Target /usr/local/bin/redis-benchmark
already exists. You may want to remove it:
rm '/usr/local/bin/redis-benchmark'
To force the link and overwrite all conflicting files:
brew link --overwrite redis
To list all files that would be deleted:
brew link --overwrite --dry-run redis
在这种情况下,你可以通过运行以下命令覆盖 Redis Stack 安装的 Redis 二进制文件
brew link --overwrite redis
但是,Redis Stack Server 仍然会安装。要卸载 Redis Stack Server,请参见下面。
卸载 Redis Stack
要卸载 Redis Stack,请运行
brew uninstall redis-stack-redisinsight redis-stack-server redis-stack
brew untap redis-stack/redis-stack
连接到 Redis
Redis 运行后,你可以通过运行 redis-cli
来测试它
redis-cli
使用 ping
命令测试连接
127.0.0.1:6379> ping
PONG
你也可以使用 Redis Insight 来测试你的 Redis 服务器是否正在运行。
下一步
拥有一个运行的 Redis 实例后,你可能需要
- 尝试 Redis CLI 教程
- 使用一个 Redis 客户端 连接
- 为了生产使用,正确安装 Redis。