一: 安裝redis
最簡(jiǎn)單的方式是使用brew安裝redis,如果沒有安裝brew,請(qǐng)自行安裝
chen$ brew install redis
==> Caveats
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
?? /usr/local/Cellar/redis/5.0.3: 13 files, 3.1MB
==> `brew cleanup` has not been run in 30 days, running now...
等待安裝完畢即可。注意安完畢后,日志里會(huì)打印redis的安裝目錄,我的安裝目錄在 /usr/local/Cellar/redis/5.0.3
二:?jiǎn)?dòng)redis
- 方式一 進(jìn)入redis安裝目錄,直接執(zhí)行redis-srver
chenxiangmingdeMacBook-Air:~ chen$ cd /usr/local/Cellar/redis/5.0.3/
chenxiangmingdeMacBook-Air:5.0.3 chen$ redis-server
54166:C 04 Mar 2019 19:41:18.961 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
54166:C 04 Mar 2019 19:41:18.961 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=54166, just started
54166:C 04 Mar 2019 19:41:18.961 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
54166:M 04 Mar 2019 19:41:18.963 * Increased maximum number of open files to 10032 (it was originally set to 2560).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 54166
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
54166:M 04 Mar 2019 19:41:18.968 # Server initialized
54166:M 04 Mar 2019 19:41:18.969 * Ready to accept connections
- 方式二 使用brew啟動(dòng)
chenxiangmingdeMacBook-Air:LaunchDaemons chen$ brew services start redis
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 0), reused 13 (delta 0), pack-reused 0
Unpacking objects: 100% (17/17), done.
Tapped 1 command (50 files, 62.4KB).
==> Successfully started `redis` (label: homebrew.mxcl.redis)
啟動(dòng)成功
chenxiangmingdeMacBook-Air:LaunchDaemons chen$ redis-cli
127.0.0.1:6379> 連接成功
三:安裝rdm可視化工具
mac上很多可視化連接工具都是收費(fèi)的,這里推薦一款免費(fèi)的,效果很不錯(cuò)
下載dmp文件, 點(diǎn)我下載,然后安裝在mac上即可使用

redis_cli.png
四:設(shè)置開機(jī)自啟
設(shè)置redis開機(jī)啟動(dòng),使用的是Mac的launchd(launchd由操作系統(tǒng)內(nèi)核啟動(dòng),用戶沒有權(quán)限去進(jìn)行手動(dòng)啟動(dòng),但可以使用launchctl命令來(lái)和launchd進(jìn)行交互,借此可以控制后臺(tái)守護(hù)程序的啟動(dòng)或終止),將redis作為用戶守護(hù)(User Daemon)進(jìn)程運(yùn)行在后臺(tái),用戶守護(hù)進(jìn)程是作為系統(tǒng)的一部分運(yùn)行在后臺(tái)的非圖形化程序。用戶守護(hù)進(jìn)程是不和用戶賬戶關(guān)聯(lián)的。
- 第一步 進(jìn)入redis安裝目錄,將 .plist文件拷貝到 /Library/LaunchDaemons/目錄下
chenxiangmingdeMacBook-Air:~ chen$ cd /usr/local/Cellar/redis/5.0.3/bin/
chenxiangmingdeMacBook-Air:5.0.3 chen$ sudo cp homebrew.mxcl.redis.plist /Library/LaunchDaemons/
Password:
- 第二步 將該文件載入到launchd里,使用launchctl命令,具體命令如下
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.redis.plist
- 第三步 現(xiàn)在已經(jīng)成功將redis服務(wù)加入到系統(tǒng)啟動(dòng)項(xiàng)了,輸入以下命令可以啟動(dòng)redis
sudo launchctl start homebrew.mxcl.redis
- 關(guān)閉redis命令如下
sudo launchctl stop homebrew.mxcl.redis
- 是不是發(fā)現(xiàn)名字太長(zhǎng)了,不方便輸入和記憶,那么我們可以設(shè)置它的別名
- 編輯.bash_profile,此文件在自己的用戶根目錄下 比如我的就在/chen/目錄下
alias redis-start='sudo launchctl start homebrew.mxcl.redis'
alias redis-stop='sudo launchctl stop homebrew.mxcl.redis'
在配置文件中加入這2句代碼,然后輸入以下命令刷新資源
source ~/.bash_profile
直接使用別名即可啟動(dòng)對(duì)應(yīng)的服務(wù)
redis-start 即可直接啟動(dòng)redis服務(wù)