Redis安装和使用

本篇文章主要讲述了Mac下Redis的安装和使用的经验
linux安装redis,请移步:这里

1、使用Homebrew安装命令

brew install redis

执行上述命令后出现以下,则成功安装:

==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/redis-6.0.1
######################################################################## 100.0%
==> Pouring redis-6.0.1.mojave.bottle.tar.gz
==> 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/6.0.1: 13 files, 3.7MB

2、查看安装及配置文件位置

  • Homebrew安装的软件会默认在/usr/local/Cellar/路径下
  • redis的配置文件redis.conf存放在/usr/local/etc路径下

3、启动redis服务

brew services start redis

这个命令会在后台启动redis服务,并且每一次登录系统,都会自动重启
假如你不需要后台启动服务,你可以使用配置文件启动

redis-server /usr/local/etc/redis.conf

这个命令会读取redis的配置文件,并且在redis运行的过程中也会看到实时的日志打印。启动成功,如下所示:

9019:C 10 Dec 2020 13:38:47.881 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9019:C 10 Dec 2020 13:38:47.881 # Redis version=6.0.8, bits=64, commit=00000000, modified=0, pid=9019, just started
9019:C 10 Dec 2020 13:38:47.881 # Configuration loaded
9019:M 10 Dec 2020 13:38:47.882 * Increased maximum number of open files to 10032 (it was originally set to 256).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.0.8 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9019
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

9019:M 10 Dec 2020 13:38:47.883 # Server initialized
9019:M 10 Dec 2020 13:38:47.884 * Loading RDB produced by version 6.0.8
9019:M 10 Dec 2020 13:38:47.884 * RDB age 8 seconds
9019:M 10 Dec 2020 13:38:47.884 * RDB memory usage when created 1.03 Mb
9019:M 10 Dec 2020 13:38:47.884 * DB loaded from disk: 0.001 seconds
9019:M 10 Dec 2020 13:38:47.884 * Ready to accept connections
^C9019:signal-handler (1607578821) Received SIGINT scheduling shutdown...
9019:M 10 Dec 2020 13:40:21.289 # User requested shutdown...
9019:M 10 Dec 2020 13:40:21.289 * Saving the final RDB snapshot before exiting.
9019:M 10 Dec 2020 13:40:21.291 * DB saved on disk
9019:M 10 Dec 2020 13:40:21.291 * Removing the pid file.
9019:M 10 Dec 2020 13:40:21.291 # Redis is now ready to exit, bye bye...

4、查看redis后台事实日志

//执行以下命令
redis-server

5、查看redis服务进程

我们可以通过下面命令查看redis是否正在运行

ps axu | grep redis

6、关闭redis服务

正确停止Redis的方式应该是向Redis发送SHUTDOWN命令

redis-cli shutdown

强行终止redis

sudo pkill redis-server
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夏天的一朵云

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值