AWS launched Elasticache (EC) support for Redis. Redis is a fast, open-source, in-memory, key-value data store. Because of its fast performance, Redis is a popular choice for caching.
An EC cluster Redis can be created with a different structure.
Single node. There is a one-to-one relationship between a node and a cache cluster.
Cluster with Replica Nodes - cluster mode disabled. The cluster supports replication with a single shard
Cluster with Replica Nodes - cluster mode enabled. The cluster supports replication with multiple shards
Security and Encryption
The service offers encryption In transit and at rest. Redis AUTH for secure internode communications helps keep sensitive data safe. User groups can be used to set up user group based access control.
Different terminology between AWS Console and API/CLI.
Multi AZ and Autofailover
When Multi-AZ is enabled
- ElastiCache detects the primary node failure.
- ElastiCache promotes the read replica node with the least replication lag to primary node.
- The other replicas sync with the new primary node.
- ElastiCache spins up a read replica in the failed primary's AZ.
- The new node syncs with the newly promoted primary.
- Failing over to a replica node is generally faster than creating and provisioning a new primary node. This means your application can resume writing to your primary node sooner than if Multi-AZ were not enabled.
if Multi-AZ is enabled, the downtime is minimized. The role of primary node will automatically fail over to one of the read replicas.
Connect to a cluster
Connecting to a cluster mode disabled unencrypted-cluster
Connecting to an Encryption/Authentication enabled cluster
By default, redis-cli uses an unencrypted TCP connection when connecting to Redis. The option BUILD_TLS=yes enables SSL/TLS
You can use the option --tls with redis-cli to connect to both cluster mode enabled and disabled encrypted clusters. If a cluster has an AUTH token set, then you can use the option -a to provide an AUTH password.
The following example connects to an encryption and authentication enabled cluster:
The following example connects to a cluster that has only encryption enabled:
Redis-cli alternative
make a connection to the cluster for a short test but without going through the redis-cli compilation, you can use telnet or openssl
Doesn't have encryption
If the cluster has a password set, first connect to the cluster.
Create resource as code Cloudformation
Prerequisites
Cluster single node, cluster mode disabled
CacheClusterSingleNode:
Type: AWS::ElastiCache::CacheCluster
Properties:
CacheNodeType: cache.t2.micro
CacheParameterGroupName: !Ref ParameterGroup
CacheSubnetGroupName: !Ref SubnetGroup
ClusterName: !Join ['-', [!Ref ServiceNameDatabase, 'single-node']]
Engine: redis
EngineVersion: 6.2
NumCacheNodes: 1
Port: 6379
Tags:
- Key: Name
Value: !Join ['-', [!Ref ServiceNameDatabase, 'single-node']]
VpcSecurityGroupIds:
- sg-xxxxxxxxxxxxxxx
Cluster with replication group, cluster mode disabled
CacheClusterReplicaGroupClusterModeDisable:
Type: AWS::ElastiCache::ReplicationGroup
Properties:
AtRestEncryptionEnabled: true
AutomaticFailoverEnabled: true
CacheNodeType: cache.t2.micro
CacheParameterGroupName: !Ref ParameterGroup
CacheSubnetGroupName: !Ref SubnetGroup
Engine: redis
EngineVersion: 6.2
MultiAZEnabled: true
Port: 6379
NumCacheClusters: 2 # NumCacheClusters is the number of nodes in a shard
ReplicationGroupDescription: ReplicationGroupDescription
# ReplicationGroupId: !Join ['-', [!Ref ServiceNameDatabase, 'replication-group-mode-disable']]
ReplicationGroupId: !Join ['-', [!Ref ServiceNameDatabase, 'replication-group']]
SecurityGroupIds:
- sg-xxxxxxxxxxx
Tags:
- Key: Name
Value: !Join ['-', [!Ref ServiceNameDatabase, 'replication-group']]
TransitEncryptionEnabled: true
Cluster with replication group, cluster mode enabled
Basic Admin Commands to handle the key-values and monitor the cluster
Go to the interactive console
redis-cli -h $REDIS_HOST -p $REDIS_PORT
-n set the database (from 0 to 16)
Info
redis-cli -h $REDIS_HOST -p $REDIS_PORT info |
Stats
--stat Print rolling stats about server: mem, clients, ...
Monitor
MONITOR is a debugging command that streams back every command processed by the Redis server. It can help in understanding what is happening to the database.
Client List
The CLIENT LIST command returns information and statistics
about the client connections server in a mostly human readable format.
References
- Getting started
- Fault Tolerance & MultiAZ
- Auto Failover
- Connect to a cluster
- Redis Terminology
- CFN Create cluster
- CFN Create replication group
- CFN Parameter group
