• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

mac系统下Redis安装和使用

武飞扬头像
前热火球员LeBron James
帮助3

一、redis 安装 和启动

用brew安装
1.查看系统是否已经安装了Redis

brew info redis

这个命令会展示此系统下的redis信息,如果没有安装,会展示not install

2.输入命令安装Redis

brew install redis

可能需要等一会,系统下载完redis的包,会自动进行安装

3.启动redis

brew services start redis

这个命令会在后台启动redis服务,并且每一次登录系统,都会自动重启

4.假如你不需要后台启动服务,你可以使用配置文件启动:

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

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

52462:C 26 Oct 2022 14:35:16.933 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
52462:C 26 Oct 2022 14:35:16.933 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=52462, just started
52462:C 26 Oct 2022 14:35:16.933 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
52462:M 26 Oct 2022 14:35:16.934 * Increased maximum number of open files to 10032 (it was originally set to 2560).
52462:M 26 Oct 2022 14:35:16.934 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 7.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 52462
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'              
学新通

5.连接redis
需要新打开一个终端,再输入如下的命令:

# 不需要身份认证时
redis-cli -p 6379 -h 127.0.0.1

# 需要身份认证时,输入如下命令
redis-cli -p 6379 -h 127.0.0.1 -a yourpassword
# or
redis-cli -p 6379 -h 127.0.0.1
# 登录进去之后再进行身份认证
127.0.0.1:6379> auth 0903

官网下载安装包进行安装
下载稳定版安装包:redis官网下载,选择Stable版本进行安装Latest Stable

下载完成后进入到安装包的目录,依次输入如下的命令:

# 移动
sudo mv redis-stable.tar.gz /usr/local
# 切换到目录
cd /usr/local
# 解压
sudo tar zxvf redis-stable.tar.gz
# 切换到redis-stable目录
cd redis-stable
# 编译测试
sudo make test
# 编译安装
sudo make install

执行sudo make install,看到下面结果安装成功:

(base) cuixin@cuixindeMacBook-Pro redis-stable % sudo make install
cd src && /Applications/Xcode.app/Contents/Developer/usr/bin/make install
/bin/sh: pkg-config: command not found
    CC Makefile.dep
/bin/sh: pkg-config: command not found
    INSTALL redis-sentinel
    INSTALL redis-check-rdb

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli

redis的启动和停止
启动redis:redis-server

(base) cuixin@cuixindeMacBook-Pro etc % redis-server 
52462:C 26 Oct 2022 14:35:16.933 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
52462:C 26 Oct 2022 14:35:16.933 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=52462, just started
52462:C 26 Oct 2022 14:35:16.933 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
52462:M 26 Oct 2022 14:35:16.934 * Increased maximum number of open files to 10032 (it was originally set to 2560).
52462:M 26 Oct 2022 14:35:16.934 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 7.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 52462
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

52462:M 26 Oct 2022 14:35:16.935 # WARNING: The TCP backlog setting of 511 cannot be enforced because kern.ipc.somaxconn is set to the lower value of 128.
52462:M 26 Oct 2022 14:35:16.935 # Server initialized
52462:M 26 Oct 2022 14:35:16.936 * Ready to accept connections
学新通

链接redis:

(base) cuixin@cuixindeMacBook-Pro redis-stable % redis-cli -p 6379 -h 127.0.0.1
127.0.0.1:6379> set name 'james'
OK
127.0.0.1:6379> get name
"james"
127.0.0.1:6379> 

参考链接:mac安装redis教程

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfhfjkc
系列文章
更多 icon
同类精品
更多 icon
继续加载