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
说明确实已关闭