mac 安装使用redis

安装redis

redis的安装方法有2种
下载源码编译安装和使用homebrew安装。
采用后一种方法,通过homebrew安装redis:

$ brew install redis

从以上日志输出可以看出,如果需要给redis服务端指定配置文件,启动命令应该是这样的:
$ redis-server /usr/local/etc/redis.conf
安装完成后redis默认的配置文件redis.conf位于
/usr/local/etc

使用cat命令查看redis.conf: $ cat /usr/local/etc/redis.conf

启动redis

可以通过以下命令启动redis:
$ redis-server /usr/local/etc/redis.conf
终端输出
这里写图片描述
可以看出redis服务器启动成功,并在监听6379端口的网络连接。
注意: 使用命令$ redis-server也可以启动,此时并不会加载任何配置文件,使用的是程序中内置(built-in)的默认配置.

检测redis是否启动

重新打开一个终端窗口,输入命令
$ redis-cli ping
该终端输出
pong
说明服务器运作正常。

关闭redis

关闭redis有2种方法:

方法1
在执行启动命令的终端窗口使用ctrl+c,此时第一个窗口输出

8773:M 11 Sep 21:46:26.581 # User requested shutdown…
8773:M 11 Sep 21:46:26.581 * Saving the final RDB snapshot before exiting.
8773:M 11 Sep 21:46:26.583 * DB saved on disk
8773:M 11 Sep 21:46:26.583 * Removing the pid file.
8773:M 11 Sep 21:46:26.583 # Redis is now ready to exit, bye bye…
然后在另外一个终端窗口执行$ redis-cli ping,输出
Could not connect to Redis at 127.0.0.1:6379: Connection refused
说明确实已关闭

方法2
在另外一个终端窗口执行$ redis-cli shutdown,此时第一个窗口输出

8773:M 11 Sep 21:46:26.581 # User requested shutdown…
8773:M 11 Sep 21:46:26.581 * Saving the final RDB snapshot before exiting.
8773:M 11 Sep 21:46:26.583 * DB saved on disk
8773:M 11 Sep 21:46:26.583 * Removing the pid file.
8773:M 11 Sep 21:46:26.583 # Redis is now ready to exit, bye bye…
然后在另外一个终端窗口执行$ redis-cli ping,输出
Could not connect to Redis at 127.0.0.1:6379: Connection refused
说明确实已关闭

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值