I want to troubleshoot my Redis backup (.rdb) file that's smaller than the BytesUsedForCache metric in my ElastiCache for Redis self-designed cluster?
Resolution
The BytesUsedForCache metric includes bytes for all purposes, such as actual key size, headers, and memory fragmentation. Also, expired keys also consume memory until Redis removes them asynchronously, either passively or actively. For more information, see EXPIRE on the Redis website.
ElastiCache uses fork and forkless backup processes that dump all keys on the disk to create your .rdb file. Your .rdb file might be smaller than the BytesUsedForCache metric because the file doesn't use pointers or expired keys. The file also doesn't include memory fragmentation, metadata, and buffers.
For example, suppose your Redis cluster shows BytesUsedForCache as 15 GiB. If your backup was initiated when there were heavy read and write requests, then that cache size might range from 10 GiB to 12 GiB. This is because the backup doesn't include expired keys, pointers, memory fragmentation, metadata, and buffers.
To confirm the data integrity of your backup, use the Redis Keyspace or DBSIZE commands. For more information, see Keyspace and DBSIZE on the Redis website. Compare the number of keys that are in the original cluster and restored cluster to the .rdb file. Make sure that no key insert, deletion, or eviction actions occurred between the snapshot creation and restore. For more information, see Why does my replica have a different number of keys than its master instance? on the Redis website.
Note: The cache size in ElastiCache backups is based on the Redis used_memory parameter at the time of snapshot. That size is an estimate of the uncompressed cache size. For more information, see INFO on the Redis website. If you export a backup snapshot to Amazon Simple Storage Service (Amazon S3), then the compressed serialized file size is exported.
Related information
Snapshot and restore