欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Redis安装和使用

程序员文章站 2022-03-22 15:37:35
本篇文章主要讲述了Mac下Redis的安装和使用的经验1、使用Homebrew安装命令brew install redis执行上述命令后出现以下,则成功安装:==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/redis-6.0.1######################################################################## 100.0%==> P...

本篇文章主要讲述了Mac下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

本文地址:https://blog.csdn.net/ximenxiafeng/article/details/110951391

相关标签: 数据库 redis