文章目录

  • 引言
  • 安装
  • 前置条件
  • 安装Redis
  • 操作
  • 启动
  • 验证
  • 停止



关注微信公众号:CodingTechWork,一起学习进步。

引言

  本文主要介绍macOS系统如何使用Homebrew安装和启动redis服务。

安装

前置条件

首先需要保证你的mac电脑安装了Homebrew,我们可以通过以下命令进行校验

$ brew --version

显示结果

hugh@xxx brew --version
Homebrew 3.4.9-33-g3088bbf
Homebrew/homebrew-core (git revision ca10e12c01f; last commit 2022-05-01)
Homebrew/homebrew-cask (git revision c712bf4e66; last commit 2022-05-01)

若显示报错,则需要安装Homebrew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装Redis

$ brew install redis

操作

启动

$ redis-server

或者

$ brew services start redis
hugh@bogon ~ % brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)
hugh@bogon ~ % lsof -i:6379
COMMAND     PID       USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
redis-ser 70279 liaojianya    6u  IPv4 0xd856625383e21061      0t0  TCP localhost:6379 (LISTEN)
redis-ser 70279 liaojianya    7u  IPv6 0xd85662537c5bfa31      0t0  TCP localhost:6379 (LISTEN)

验证

  1. 通过brew services info redis命令查看redis信息
hugh@bogon ~ % brew services info redis
redis (homebrew.mxcl.redis)
Running: ✔
Loaded: ✔
Schedulable: ✘
User: hugh
PID: 69410
  1. 通过命令行redis-cli校验
hugh@bogon ~ % redis-cli
127.0.0.1:6379> set key01 hello-world
OK
127.0.0.1:6379> get key01
"hello-world"

停止

通过brew services stop redis命令停止redis

hugh@bogon ~ % brew services stop redis
Stopping `redis`... (might take a while)
==> Successfully stopped `redis` (label: homebrew.mxcl.redis)

通过brew services info redis命令查看redis

hugh@bogon ~ % brew services info redis
redis (homebrew.mxcl.redis)
Running: ✘
Loaded: ✘
Schedulable: ✘