AWS — ElastiCache
What is ElastiCache?
Managed in-memory caching service supporting Redis and Memcached.
Create Redis cluster
aws elasticache create-cache-cluster \
--cache-cluster-id my-redis \
--cache-node-type cache.t2.micro \
--engine redis \
--num-cache-nodes 1
Create Memcached cluster
aws elasticache create-cache-cluster \
--cache-cluster-id my-memcached \
--cache-node-type cache.t2.micro \
--engine memcached \
--num-cache-nodes 2
Connect (Python)
import redis
r = redis.Redis(
host='my-redis.xxxx.cache.amazonaws.com',
port=6379,
decode_responses=True
)
r.set('key', 'value')
print(r.get('key'))
Common operations
# Strings
r.set('name', 'John')
r.get('name')
r.incr('counter')
# Hashes
r.hset('user:1', 'name', 'John')
r.hget('user:1', 'name')
# Lists
r.lpush('queue', 'task1')
r.rpop('queue')
# Sets
r.sadd('tags', 'python', 'aws')
r.smembers('tags')
Replication
aws elasticache create-replication-group \
--replication-group-id my-replication \
--replication-group-description "My replication" \
--num-cache-clusters 2
Best practices
- Use encryption in transit
- Enable encryption at rest
- Set up automatic failover
- Monitor with CloudWatch
Mini Practice
- Create a Redis cluster
- Store and retrieve data
- Use different data types
- Set up replication
Up Next
Continue with SES - Email Service.
Related Topics
Frequently Asked Questions about ElastiCache
What is ElastiCache in AWS?
ElastiCache is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn ElastiCache?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn ElastiCache.
Why is ElastiCache important in AWS?
ElastiCache is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.