liveBook · Manning

Redis cluster

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A Redis cluster is a distributed deployment of Redis nodes that partitions data across nodes and supports scalable operation.

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

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Compares replication, sharding, capacity, throughput, endpoints, and failover, then stops short of detailed cluster internals.
Examples
Uses an expiring gamer session and a sorted high-score list tested through Redis CLI.
What you can do after
Operate a Redis cache through CloudFormation, Session Manager, redis-cli, and a selected cluster deployment mode.
How it connects
Connects caching with data replication, backups, sharding, replicas, high availability, failover, and CloudFormation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.