在 macOS 上安装 Redis Stack
如何在 macOS 上安装 Redis Stack
Redis 开源版 |
---|
要在 macOS 上安装 Redis Stack,请使用 Homebrew。请确保您已安装 Homebrew,然后再开始按照以下安装说明操作。
有三个可用的 brew cask。
redis-stack
包含redis-stack-server
和redis-stack-redisinsight
cask。redis-stack-server
仅提供 Redis Stack 服务器。redis-stack-redisinsight
包含 Redis Insight。
使用 Homebrew 安装
首先,添加 Redis Stack Homebrew tap
brew tap redis-stack/redis-stack
接下来,运行 brew install
brew install redis-stack
redis-stack-server
cask 将安装所有 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 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 服务器
您现在可以按如下方式启动 Redis Stack 服务器
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 服务器仍将保持安装状态。要卸载 Redis Stack 服务器,请参阅下文。
卸载 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。