ノードに接続する - Amazon ElastiCache for Redis

ノードに接続する

Redis クラスターのノードに接続を試みる前に、ノードのエンドポイントが必要です。エンドポイントを見つけるには、以下を参照してください。

次の例では、redis-cli ユーティリティを使用して Redis を実行しているクラスターに接続します。

注記

Redis と使用可能な Redis のコマンドの詳細については、http://redis.io/commands ウェブページを参照してください。

redis-cli を使用して Redis クラスターに接続するには
  1. 選択した接続ユーティリティを使用して、Amazon EC2 インスタンスに接続します。

    注記

    Amazon EC2 インスタンスに接続する方法については、「Amazon EC2 入門ガイド」を参照してください。

  2. redis-cli をビルドするには、GNU Compiler Collection (gcc) をダウンロードしてインストールします。EC2 インスタンスのコマンドプロンプトで、以下のコマンドを入力します。確認のプロンプトが表示されたら、「y」と入力します。

    sudo yum install gcc

    以下のような出力が表示されます。

    Loaded plugins: priorities, security, update-motd, upgrade-helper Setting up Install Process Resolving Dependencies --> Running transaction check ...(output omitted)... Total download size: 27 M Installed size: 53 M Is this ok [y/N]: y Downloading Packages: (1/11): binutils-2.22.52.0.1-10.36.amzn1.x86_64.rpm | 5.2 MB 00:00 (2/11): cpp46-4.6.3-2.67.amzn1.x86_64.rpm | 4.8 MB 00:00 (3/11): gcc-4.6.3-3.10.amzn1.noarch.rpm | 2.8 kB 00:00 ...(output omitted)... Complete!
  3. redis-cli ユーティリティをダウンロードし、コンパイルします。このユーティリティは Redis ソフトウェアディストリビューションに含まれています。EC2 インスタンスのコマンドプロンプトで、以下のコマンドを入力します。

    注記

    Ubuntu システムでは、make を実行する前に、make distclean を実行します。

    wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make distclean # ubuntu systems only make
  4. EC2 インスタンスのコマンドプロンプトで、次のコマンドを入力します。

    src/redis-cli -c -h mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com -p 6379

    以下のような Redis コマンドのプロンプトが表示されます。

    redis mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 6379>
  5. Redis コマンドを実行して接続をテストします。

    これで、クラスターに接続され、Redis のコマンドを実行できます。以下に一部のコマンドとその Redis レスポンスの例を示します。

    set a "hello" // Set key "a" with a string value and no expiration OK get a // Get value for key "a" "hello" get b // Get value for key "b" results in miss (nil) set b "Good-bye" EX 5 // Set key "b" with a string value and a 5 second expiration get b "Good-bye" // wait 5 seconds get b (nil) // key has expired, nothing returned quit // Exit from redis-cli

Secure Sockets Layer (SSL) 暗号化 (転送中の暗号化) が有効なノードまたはクラスターへの接続については、「ElastiCache の転送時の暗号化 (TLS)」を参照してください。