A Redis cluster is a distributed Redis deployment that stores data across nodes. In managed AWS terminology, cluster, node, and shard correspond roughly to replication group, node, and node group in the API, CLI, and CloudFormation. section 11.2.3
Choose a deployment mode according to data size, availability, and throughput needs:
- Cluster mode disabled keeps all data in one shard, with one primary synchronized to one through five replicas. It provides backups and replication when the dataset fits on one node. section 11.2.3
- Cluster mode enabled supports backups, replication, and sharding. Each shard has a primary and optional replicas, allowing data and traffic to spread across nodes. section 11.2.4
- Adding shards increases total memory and read/write throughput. It also limits a failover's affected key space, although writes to that portion pause during recovery. section 11.2.4
- Cluster mode enabled discovers topology changes through a configuration endpoint and can fail over in less than 30 seconds; disabled mode relies on a DNS swap that may take about 1–1.5 minutes. section 11.2.4
Session and high-score cache
After a CloudFormation stack reaches CREATE_COMPLETE, connect to its EC2 instance through Session Manager, install Redis 6, and use redis-cli with the cache address. Store a temporary session with SET session:gamer1 online EX 15, observe it expire, then use ZADD and ZRANGE to maintain and read a scored high-score list. Delete the stack when finished. section 11.1.2
$ sudo amazon-linux-extras install -y redis6 #1 $ redis-cli -h $CacheAddress #2 > SET session:gamer1 online EX 15 #3 OK > GET session:gamer1 #4 "online" > GET session:gamer1 #5 (nil) #6 > ZADD highscore 100 "gamer1" #7 (integer) 1 > ZADD highscore 50 "gamer2" #8 (integer) 1 > ZADD highscore 150 "gamer3" #9 (integer) 1 > ZADD highscore 5 "gamer4" #10 (integer) 1 > ZRANGE highscore -3 -1 WITHSCORES #11 1) "gamer2" #12 2) "50" 3) "gamer1" 4) "100" 5) "gamer3" 6) "150" > quit #13
Shows the smallest useful Redis CLI sequence for installing the client, testing expiration, and working with a sorted set. section 11.1.2
