Mac システムで Redis をインストールして使用するための詳細な手順

この記事では主に、Mac に Redis をインストールする 2 つの方法とその使用体験について説明します。1 つ目は、brew を使用してインストールします (ネットワーク上の理由により、正常にダウンロードできず、インストールが失敗した可能性があります)。 2 つ目は、公式 Web サイトからインストール パッケージをダウンロードすることです。

1. Redisのインストールと起動

brew
1 でインストールします。システムに Redis がインストールされているかどうかを確認します

brew info redis

このコマンドは、このシステムの Redis 情報を表示します。インストールされていない場合は、「インストールされていません」と表示されます。

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

インストール用の公式 Web サイトからインストール パッケージをダウンロードします
。 安定版のインストール パッケージをダウンロードします。 Redis 公式 Web サイトからダウンロードし、安定版を選択して最新の安定版をインストールします

ダウンロードが完了したら、インストール パッケージのディレクトリに移動し、次のコマンドを順番に入力します。

# 移动
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チュートリアル

おすすめ

転載: blog.csdn.net/qq_34663267/article/details/127532218