liveBook · Manning

Redis

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

Redis is an in-memory data structure server that provides persistent and non-persistent key-value data storage and access.

Redis is an in-memory database for fast reads and writes. It can serve as a cache in front of a relational database, reducing database traffic and application latency. Unlike a simple key-value cache, it supports complex data structures such as sorted sets. section 11.0 section 11.7

A game leaderboard

A game can keep its primary records in a relational database while maintaining a working leaderboard in a Redis sorted set. Scores determine the order as entries are inserted; `ZREVRANGE "player-scores" 0 9` retrieves the top ten without sorting millions of records in the primary database. section 11.0

Choose an AWS deployment according to the workload:

  • ElastiCache for Redis, single node: supports backup and restore, but not replication or sharding. The node is a single point of failure. section 11.2.2
  • ElastiCache for Redis, cluster mode disabled: adds replication but not sharding. Cluster mode enabled adds both. section 11.2
  • MemoryDB: offers Redis compatibility, replication, sharding, and stronger persistence guarantees. section 11.2 section 11.7

To provision a single-node ElastiCache cluster with CloudFormation, define an `AWS::ElastiCache::CacheCluster` with `Engine: redis`, a node type, `NumCacheNodes: 1`, a subnet group, and security groups. ElastiCache nodes have private IP addresses; test connectivity from an EC2 instance in the same VPC rather than from the internet. section 11.1.1

Secure management and data access separately. IAM governs cluster administration; security groups govern network traffic. Redis can authenticate clients with a shared token or, in versions above 6.0, use role-based access control to give clients different permissions. Enable in-transit encryption when using authentication so secrets are not sent in plain text. section 11.3 section 11.3.3

A forum cache

Discourse uses PostgreSQL as its main data store and Redis for cached and transient data. A CloudFormation deployment combines the cache, database, networking, and EC2 instance; once running, monitor ElastiCache utilization and performance with CloudWatch. section 11.4 section 11.4.5 section 11.7

A cache still needs a freshness strategy: let entries expire or use write-through updates to keep it aligned with the database. When full, it may evict less-used items. Weigh those behaviors alongside availability, memory capacity, throughput, and persistence requirements before choosing a deployment. section 11.7 section 11.2

Table 11.2 Comparing ElastiCache and MemoryDB engines and deployment options (view table figure)

Service

Engine

Deployment Option

Backup/Restore

Replication

Sharding

ElastiCache

Memcached

Default

No

No

Yes

 

Redis

Single Node

Yes

No

No

 

 

Cluster Mode disabled

Yes

Yes

No

 

 

Cluster Mode enabled

Yes

Yes

Yes

MemoryDB

Redis

Default

Yes

Yes

Yes

Compare backup and restore, replication, and sharding across ElastiCache and MemoryDB deployment options. section 11.2

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

How deep it goes
Works through deployment choices, a minimal CloudFormation cluster, access controls, and application use rather than Redis engine internals.
Examples
Shows a game leaderboard, a single-node CloudFormation cluster, and a Discourse forum using Redis with PostgreSQL.
What it assumes
Assumes familiarity with relational databases and AWS networking while identifying the CloudFormation resources needed for a first cluster.
What you can do after
Operate/configure it through ElastiCache deployment and access choices, then monitor its role in an application.
How it connects
Connects Redis to sorted sets, relational databases, ElastiCache, MemoryDB, IAM, security groups, and CloudWatch.

Also explained in

Compare how 6 books explain Redis →

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.