sashoalm
sashoalm

Reputation: 79467

What happens if elasticache memory capacity is exceeded?

I have a cache.t4g.micro cluster which has with 0.5 GiB memory (I assume this is RAM memory).

What happens if I try to add more data than that? Would that be written to HDD/SSD storage (but the docs don't mention such storage, only RAM), or would StringSetAsync() simply fail? Or maybe the oldest key/value pair would be removed from the cache to make room?

Basically what happens if storage capacity is exceeded in ElastiCache?

Upvotes: 1

Views: 1828

Answers (1)

Tasos P.
Tasos P.

Reputation: 4114

Redis keeps its entire dataset in memory (why?).

Redis behavior when memory storage is exceeded depends on maxmemory-policy configuration (documentation here).

Possible values for maxmemory-policy are (source: redis.conf):

  • volatile-lru -> remove the key with an expire set using an LRU algorithm
  • allkeys-lru -> remove any key according to the LRU algorithm
  • volatile-random -> remove a random key with an expire set
  • allkeys-random -> remove a random key, any key
  • volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  • noeviction -> don't expire at all, just return an error on write operations

When it comes to AWS ElastiCache, Redis engine is configured via Parameter Groups.

The default parameter group default.redis6.x for example specifies a value of volatile-lru for maxmemory-policy but you can create your own parameter group and change this value as you see fit.

Upvotes: 2

Related Questions