To connect to an ElastiCache Redis cluster, you need to do the following steps:
Here's a step-by-step guide with code examples:
Navigate to the ElastiCache section of the AWS Management Console to locate your Redis cluster. Click on the cluster name, and find the "Primary Endpoint" under the details tab.
Ensure you have redis-cli
installed on your local machine or application server. For example, on Ubuntu, you can use the following command to install it:
sudo apt-get install redis-tools
For Python applications, you will need to install the redis
package:
pip install redis
redis-cli
:Connect to the ElastiCache Redis cluster with the redis-cli
tool:
redis-cli -h <REDIS_HOST> -p <REDIS_PORT>
Replace <REDIS_HOST>
and <REDIS_PORT>
with your cluster's endpoint address and port, respectively.
In a Python script, use the redis
library to connect to the ElastiCache Redis cluster:
import redis
# Replace <REDIS_HOST> and <REDIS_PORT> with your cluster's endpoint address and port, respectively.
redis_host = "<REDIS_HOST>"
redis_port = <REDIS_PORT>
r = redis.Redis(host=redis_host, port=redis_port)
# Test the connection
response = r.ping()
print("Connected to Redis:", response)
Now that you've successfully connected to your ElastiCache Redis cluster, you can perform operations like reading and writing data using the Redis commands available in your chosen client.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.