Why does my Amazon ElastiCache Redis cluster primary node have more items than a read-only replica secondary node?

Last updated: 2019-04-22

The primary read/write node of my ElastiCache Redis (cluster mode disabled) cluster has more keys than a secondary read-only replica node. This discrepancy can be observed with the Amazon CloudWatch CurrItems metric or the Redis DBSIZE command. What causes this discrepancy?


This discrepancy can occur after adding a read replica to an ElastiCache Redis (cluster mode disabled) cluster that contains a large number of keys with TTL (time-to-live) values that have expired. The read replica issues a ‘sync’ command to obtain an RDB file snapshot of the primary node’s contents. When the read replica loads this RDB file into memory, it discards any keys that have expired.

This behavior is by design because Redis keys are expired both actively and passively as described at How Redis expires keys.

Did this article help you?

Anything we could improve?

Need more help?