Redis

380 阅读1分钟

官网

安装

用homebrew安装

arm64安装:

arch -arm64 brew install redis

查看redis信息(版本号,目录等)

brew info redis

目录:/opt/homebrew/Cellar/redis/7.0.0

可执行文件目录(软链接):/opt/homebrew/opt/redis/bin

/opt/homebrew/opt/redis 指向 /opt/homebrew/Cellar/redis/7.0.0

另一个可执行文件目录:/opt/homebrew/bin/redis-server 也是指向 /opt/homebrew/Cellar/redis/7.0.0/bin/redis-server

image.png

启动

前台启动:

redis-server

执行的是/opt/homebrew/bin/redis-server。
which redis-server,显示 /opt/homebrew/bin/redis-server。
因为/opt/homebrew/bin:/opt/homebrew/sbin在环境变量PATH中。

停止Redis:ctrl + c

使用launchd(launchd由操作系统内核启动,用户没有权限去进行手动启动)来启动和暂停Redis

brew services start redis

这样电脑重启的时候会自动启动Redis

通过这种方式启动redis,日志文件在 /opt/homebrew/log/redis.log

查看Redis启动状况

brew services info redis

暂停Redis服务

brew services stop redis

配置文件启动

原本配置文件:/opt/homebrew/etc/redis.conf

拷贝一份放在:/opt/homebrew/Cellar/redis/7.0.0/6379.conf

修改配置文件

后台启动:

daemonize yes

配置远程登录,一般配置本机登录或者局域网登录。保持默认:bing 127.0.0.1.(配置允许远程登录 bind 0.0.0.0)

端口配置:

port 6379

工作目录配置(数据库、日志等放的位置),保持默认:dir /opt/homebrew/var/db/redis/

日志文件(默认在工作目录下,这里我们放在/opt/homebrew/var/log/redis下):

logfile "../../log/redis/6379.log"

创建日志文件:

cd /opt/homebrew/var/log
mkdir redis
touch 6379.log

设置环境变量\别名

修改 ~/.zshrc

alias redis_start='redis-server /opt/homebrew/Cellar/redis/7.0.0/6379.conf'
alias redis_stop='redis-cli shutdown'

source .zshrc

启动/停止

启动:

redis_start

查看日志/opt/homebrew/var/log/redis/6379.log:

image.png

查看PID:

lsof -nP -i | grep redis

非正常停止:

kill -9 49986

正常停止:

redis_stop