Menu
Amazon ElastiCache
User Guide (API Version 2015-02-02)

Step 5: Connect to a Cluster's Node

Before you continue, be sure you have completed Step 4: Authorize Access.

This section assumes that you've created an Amazon EC2 instance and can connect to it. For instructions on how to do this, go to the Amazon EC2 Getting Started Guide.

An Amazon EC2 instance can connect to a cluster node only if you have authorized it to do so. For more information, see Step 4: Authorize Access.

Step 5.1: Find your Node Endpoints

Once your cluster is in the available state and you've authorized access to it, you can log in to an Amazon EC2 instance and connect to a node in the cluster. To do so, you must first determine the node endpoint.

To find your node's endpoints, see the relevant topic. When you find the endpoint you need, copy it to your clipboard for use in Step 5.2.

Step 5.2: Connect to a Memcached Node

Now that you have an endpoint, you can log in to an Amazon EC2 instance and connect to the cache node. The procedure depends on the engine that you are using:

In the following example, you use the telnet utility to connect to a node that is running Memcached.

Note

For more information about Memcached and available Memcached commands, see the Memcached website.

To connect to a node using telnet

  1. Connect to your Amazon EC2 instance by using the connection utility of your choice.

    Note

    For instructions on how to connect to an Amazon EC2 instance, see the Amazon EC2 Getting Started Guide.

  2. Download and install the telnet utility on your Amazon EC2 instance. At the command prompt of your Amazon EC2 instance, type the following command and type y at the command prompt.

    Copy
    sudo yum install telnet Loaded plugins: priorities, security, update-motd, upgrade-helper Setting up Install Process Resolving Dependencies --> Running transaction check ...(output omitted)... Total download size: 63 k Installed size: 109 k Is this ok [y/N]: y Downloading Packages: telnet-0.17-47.7.amzn1.x86_64.rpm | 63 kB 00:00 ...(output omitted)... Complete!
  3. At the command prompt of your Amazon EC2 instance, type the following command, substituting the endpoint of your node for the one shown in this example.

    Copy
    telnet mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 11211

    Output similar to the following appears.

    Copy
    Trying 128.0.0.1... Connected to mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com. Escape character is '^]'. >
  4. Run Memcached commands.

    You are now connected to a node, and you can run Memcached commands. The following is an example.

    Copy
    set a 0 0 5 // Set key "a" with no expiration and 5 byte value hello // Set value as "hello" STORED get a // Get value for key "a" VALUE a 0 5 hello END get b // Get value for key "b" results in miss END >

Step 5.2: Connect to a Redis Cluster or Replication Group

Now that you have the endpoint you need, you can log in to an EC2 instance and connect to the cache node. The procedure depends on the engine that you are using:

In the following example, you use the redis-cli utility to connect to a cluster that is running Redis.

Note

For more information about Redis and available Redis commands, see Redis commands webpage.

To connect to a Redis cluster using redis-cli

  1. Connect to your Amazon EC2 instance using the connection utility of your choice.

    Note

    For instructions on how to connect to an Amazon EC2 instance, see the Amazon EC2 Getting Started Guide.

  2. Before you can build redis-cli, you will need to download and install the GNU Compiler Collection (gcc). At the command prompt of your EC2 instance, type the following command and type y at the confirmation prompt.

    Copy
    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. Download and compile the redis-cli utility. This utility is included in the Redis software distribution. At the command prompt of your EC2 instance, type the following commands:

    Note

    For Ubuntu systems, prior to running make, run make distclean.

    Copy
    wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make
  4. At the command prompt of your EC2 instance, type the following command, substituting the endpoint of your cluster for the one shown in this example.

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

    A Redis command prompt similar to the following appears.

    Copy
    redis mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 6379>
  5. Run Redis commands.

    You are now connected to the cluster and can run Redis commands. The following is an example.

    Copy
    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