本文介绍在mac上使用brew安装redis。
准备:Mac 安装brew 安装item。
brew的常用命令如下:
brew search ** //查找某个软件包
brew list //列出已经安装的软件的包
brew install ** //安装某个软件包,默认安装的是稳定版本
brew uninstall ** //卸载某个软件的包
brew upgrade ** //更新某个软件包
brew info ** //查看指定软件包的说明
brew cache clean //清理缓存
搜索redis
zzpMac:~ zzp$ brew search redis
==> Formulae
hiredis redis redis-leveldb redis@3.2 redis@4.0
==> Casks
homebrew/cask/another-redis-desktop-manager homebrew/cask/redis
zzpMac:~ zzp$
安装redis ,brew会先自己更新升级,然后再下载redis
zzpMac:~ zzp$ brew install redis@3.2
Updating Homebrew...
==> Auto-updated Homebrew!
成功后会提示
To have launchd start redis@3.2 now and restart at login:
brew services start redis@3.2
Or, if you don't want/need a background service you can just run:
/usr/local/opt/redis@3.2/bin/redis-server /usr/local/etc/redis.conf
==> Summary
🍺 /usr/local/Cellar/redis@3.2/3.2.13: 13 files, 1.7MB
根据提示编辑/usr/local/etc/redis.conf
,找到daemonize no
改成yes
以守护进程的方式启动
################################# GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /usr/local/var/run/redis.pid when daemonized.
daemonize yes
修改环境变量 我编辑的是 ~/.bash_profile
文件,编辑完后
执行source ~/.bash_profile
使环境变量配置文件生效
export REDIS_HOME=/usr/local/opt/redis@3.2
export NODE_ENV=development
export PATH=$MYSQL_HOME/bin:$REDIS_HOME/bin:$PATH
执行命令 redis-server
可以看到redis已经安装成功
zzpMac:etc zzp$ redis-server
13125:C 30 Apr 11:57:25.881 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
13125:M 30 Apr 11:57:25.884 * Increased maximum number of open files to 10032 (it was originally set to 4864).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.13 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 13125
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
13125:M 30 Apr 11:57:25.887 # Server started, Redis version 3.2.13
13125:M 30 Apr 11:57:25.887 * DB loaded from disk: 0.001 seconds
13125:M 30 Apr 11:57:25.887 * The server is now ready to accept connections on port 6379
启动:brew services start redis@3.2
或者使用
redis-server /usr/local/etc/redis.conf
启动
查看进程
ps axu | grep redis
zzpMac:~ zzp$ redis-server /usr/local/etc/redis.conf
zzpMac:~ zzp$ ps axu | grep redis
zzp 13587 0.0 0.0 4286452 824 s001 S+ 12:04PM 0:00.00 grep redis
zzp 13217 0.0 0.0 4305336 716 ?? Ss 11:58AM 0:00.29 redis-server 127.0.0.1:6379
连接本地redis客户端
zzpMac:~ zzp$ redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set testkey testvalue
OK
127.0.0.1:6379> get testkey
"testvalue"
127.0.0.1:6379> del testkey
(integer) 1
127.0.0.1:6379> get testkey
(nil)
127.0.0.1:6379> exit
zzpMac:~ zzp$
关闭杀掉redis
zzpMac:~ zzp$ redis-cli shutdown
zzpMac:~ zzp$ sudo pkill redis-server
关于redis.conf
配置