Brew install redis

2020-04-19  本文已影响0人  梦想又照进现实

一、先查下机器上有没有安装redis,常见命令:

brew search **  //查找某个软件包
brew list  //列出已经安装的软件的包
brew install ** //安装某个软件包,默认安装的是稳定版本
brew uninstall **//卸载某个软件的包
brew upgrade ** //更新某个软件包
brew info ** //查看指定软件包的说明
brew cache clean //清理缓存

执行list发现么有redis,那么查下可安装的有啥版本,执行

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.

二、安装

执行 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...

三、配置

根据上面的提示进行简单配置,修改为守护进程为yes并配置path环境变量;

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

上一篇下一篇

猜你喜欢

热点阅读