Connecting to nodes
Before attempting to connect to the nodes in your Redis OSS cluster, you must have the endpoints for the nodes. To find the endpoints, see the following:
In the following example, you use the redis-cli utility to connect to a cluster that is running Redis OSS.
Note
For more information about Redis OSS and available Redis OSS commands, see the http://redis.io/commands
To connect to a Redis OSS cluster using the redis-cli
-
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.
-
To build
redis-cli
, download and install the GNU Compiler Collection (gcc
). At the command prompt of your EC2 instance, enter the following command and entery
at the confirmation prompt.sudo yum install gcc
Output similar to the following appears.
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!
-
Download and compile the redis-cli utility. This utility is included in the Redis OSS software distribution. At the command prompt of your EC2 instance, type the following commands:
Note
For Ubuntu systems, before running
make
, runmake distclean
.wget https://download.redis.io/releases/redis-7.2.5.tar.gz tar xvzf redis-7.2.5.tar.gz cd redis-7.2.5 make distclean # ubuntu systems only make
-
At the command prompt of your EC2 instance, type the following command.
src/redis-cli -c -h
mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com
-p6379
A Redis OSS command prompt similar to the following appears.
redis mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 6379>
-
Test the connection by running Redis OSS commands.
You are now connected to the cluster and can run Redis OSS commands. The following are some example commands with their Redis OSS responses.
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
For connecting to nodes or clusters which have Secure Sockets Layer (SSL) encryption (in-transit enabled), see ElastiCache in-transit encryption (TLS).