Mac「brew」快速安装Redis
安装Redis
步骤 1:安装 Redis
-
打开终端(Terminal)。
-
运行以下命令安装 Redis:
brew install redis
步骤 2:启动 Redis
-
安装完成后,可以使用以下命令启动 Redis 服务:
brew services start redis
这会将 Redis 作为后台服务启动。
-
如果需要手动启动 Redis,可以运行:
redis-server /usr/local/etc/redis.conf
步骤 3:验证 Redis 是否运行
-
使用以下命令检查 Redis 是否正常运行:
redis-cli ping
- 如果返回
PONG
,说明 Redis 已成功启动。
- 如果返回
-
如果需要连接到 Redis 服务器并执行命令,可以运行:
redis-cli
然后在 Redis CLI 中执行命令,例如:
set mykey "Hello Redis" get mykey
步骤 4:停止 Redis
-
如果需要停止 Redis 服务,可以运行:
brew services stop redis
-
如果是手动启动的 Redis,可以按
Ctrl + C
停止。
步骤 5:配置 Redis(可选)
-
Redis 的配置文件位于
/usr/local/etc/redis.conf
。 -
如果需要修改配置(如绑定地址、端口、密码等),可以编辑该文件:
修改后,重启 Redis 服务使配置生效:nano /usr/local/etc/redis.conf
brew services restart redis
步骤 6:设置 Redis 开机自启动(可选)
-
如果需要 Redis 在系统启动时自动运行,可以运行:
brew services start redis