一、先查下機器上有沒有安裝redis,常見命令:
brew search ** //查找某個軟件包
brew list //列出已經(jīng)安裝的軟件的包
brew install ** //安裝某個軟件包,默認安裝的是穩(wěn)定版本
brew uninstall **//卸載某個軟件的包
brew upgrade ** //更新某個軟件包
brew info ** //查看指定軟件包的說明
brew cache clean //清理緩存
執(zhí)行l(wèi)ist發(fā)現(xiàn)么有redis,那么查下可安裝的有啥版本,執(zhí)行
brew search redis
打印結果
appledeMacBook-Air:~ apple$ brew search redis
Warning: Error searching on GitHub: curl failed! % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (7) Failed to connect to api.github.com port 443: Connection refused
Warning: Cask 'jtool' is unreadable: undefined method `method_missing_message' for Utils:Module
Warning: Cask 'diffmerge' is unreadable: undefined method `method_missing_message' for Utils:Module
Warning: Cask 'manopen' is unreadable: undefined method `method_missing_message' for Utils:Module
Warning: Cask 'hfsleuth' is unreadable: undefined method `method_missing_message' for Utils:Module
Warning: Cask 'procexp' is unreadable: undefined method `method_missing_message' for Utils:Module
Warning: Cask 'jad' is unreadable: undefined method `method_missing_message' for Utils:Module
Warning: Cask 'mpv' is unreadable: undefined method `method_missing_message' for Utils:Module
==> Formulae
hiredis redis redis-leveldb redis@3.2 redis@4.0
==> Casks
another-redis-desktop-manager redis
If you meant "redis" specifically:
It was migrated from homebrew/cask to homebrew/core.
二、安裝
執(zhí)行 brew install redis@4.0
==> Pouring redis@4.0-4.0.14.mojave.bottle.tar.gz
==> Caveats
redis@4.0 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have redis@4.0 first in your PATH run:
echo 'export PATH="/usr/local/opt/redis@4.0/bin:$PATH"' >> ~/.bash_profile
To have launchd start redis@4.0 now and restart at login:
brew services start redis@4.0
Or, if you don't want/need a background service you can just run:
/usr/local/opt/redis@4.0/bin/redis-server /usr/local/etc/redis.conf
==> Summary
?? /usr/local/Cellar/redis@4.0/4.0.14: 13 files, 2.8MB
==> `brew cleanup` has not been run in 30 days, running now...
三、配置
根據(jù)上面的提示進行簡單配置,修改為守護進程為yes并配置path環(huán)境變量;
vi /usr/local/etc/redis.config
daemonize yes
echo 'export PATH="/usr/local/opt/redis@4.0/bin:$PATH"' >> ~/.bash_profile
四、啟動
啟動方式1:
brew services start redis@4.0
啟動方式2:
/usr/local/opt/redis@4.0/bin/redis-server /usr/local/etc/redis.conf
驗證啟動:
ps aux | grep redis
打印
appledeMacBook-Air:etc apple$ ps aux | grep redis
apple 3572 0.0 0.0 4268040 792 s001 S+ 3:51下午 0:00.00 grep redis
apple 3570 0.0 0.0 4309656 1520 ?? Ss 3:51下午 0:00.02 /usr/local/opt/redis@4.0/bin/redis-server 127.0.0.1:6379
六、連接
連接客戶端:
redis-cli -h 127.0.0.1 -p 6379
如下:
127.0.0.1:6379> get("123")
關閉
redis-cli shutdown
redis的客戶端程序redis-cli的shutdown命令來重啟redis
redis-cli -h 127.0.0.1 -p 6379 shutdown
殺死
sudo pkill redis-server