Redis安装,使用Homebrew
安装说明转载自:https://blog.csdn.net/realize_dream/article/details/106227622
1、安装Homebrew,安装国内npm
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2、使用Homebrew安装
brew install redis
安装成功
==> Downloading https://ghcr.io/v2/homebrew/core/redis/blobs/sha256:6632ef234
Already downloaded: /Users/zhangrunzhe/Library/Caches/Homebrew/downloads/dc9a85e04b7c8d0ed1d5e06325cad7211109f7826babf78e614f623a09008389--redis--6.2.5.mojave.bottle.tar.gz
==> Pouring redis--6.2.5.mojave.bottle.tar.gz
==> Caveats
To start redis:
brew services start redis
Or, if you don't want/need a background service you can just run:
/usr/local/opt/redis/bin/redis-server /usr/local/etc/redis.conf
==> Summary
🍺 /usr/local/Cellar/redis/6.2.5: 14 files, 1.9MB
zhangrunzhe@zhangrunzhedeMacBook-Pro ~/Desktop/code/go source /Users/zhangrunzhe/.zprofile
报错:
==> Installing dependencies for redis: openssl@1.1
==> Installing redis dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1l.mojave.bottle.tar.gz
tar: Error opening archive: Failed to open '/Users/zhangrunzhe/Library/Caches/Homebrew/downloads/0234724c616a2d445acb67f9492053845f862d0cc9eb76f9b6ce0ea5d22ce472--openssl@1.1-1.1.1l.mojave.bottle.tar.gz'
原因分析:
openssl@1.1
安装不成功,须手动安装,执行命令
brew install openssl@1.1
3、 查看安装及配置文件位置
- Homebrew安装的软件会默认在
/usr/local/Cellar/
路径下 - redis的配置文件
redis.conf
存放在/usr/local/etc
路径下
4、启动Redis服务
//方式一:使用brew帮助我们启动软件
brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)
//方式二
redis-server /usr/local/etc/redis.conf
//执行以下命令
redis-server
redis-server
41109:C 03 Sep 2021 15:24:00.866 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
41109:C 03 Sep 2021 15:24:00.866 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=41109, just started
41109:C 03 Sep 2021 15:24:00.866 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
41109:M 03 Sep 2021 15:24:00.868 * Increased maximum number of open files to 10032 (it was originally set to 256).
41109:M 03 Sep 2021 15:24:00.868 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 41109
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
41109:M 03 Sep 2021 15:24:00.869 # Server initialized
41109:M 03 Sep 2021 15:24:00.870 * Ready to accept connections
5、查看redis服务进程
ps axu | grep redis
6、redis-cli连接redis服务
redis默认端口号6379,默认auth为空,输入以下命令即可连接
redis-cli -h 127.0.0.1 -p 6379
7、启动redis客户端
打开终端命令输入redis-cli
$redis-cli
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
8、关闭redis服务
- 正确停止Redis的方式应该是向Redis发送SHUTDOWN命令
redis-cli shutdown
- 强行终止redis
sudo pkill redis-server
9、redis.conf
配置文件详解
redis默认是前台启动,如果我们想以守护进程的方式运行(后台运行),可以在redis.conf中将daemonize no
,修改成yes
即可。