The error message 'elasticache oom command not allowed when used memory maxmemory' is typically caused by a Redis instance reaching its maximum configured memory limit. The "OOM" in the error stands for Out Of Memory. When this happens, it means that there isn't enough available memory to execute the requested command. Redis has a configuration directive 'maxmemory' which limits the total amount of memory Redis can use. Once this maximum memory usage is reached, specific commands such as SET or HSET, which require additional memory, are not permitted.
To resolve this issue, you have several options. One would be increasing the 'maxmemory' setting. This can be done within the ElastiCache console or through the AWS CLI, though this may increase your costs. Another option is to modify the 'maxmemory-policy'. By default, it's set to 'volatile-lru', which removes the least recently used keys first, but only among keys that have an expiration set. If most of your keys do not have an expiration set, changing the policy to 'allkeys-lru' might prevent the OOM errors as it considers all keys for removal, not just those with an expiration. Ultimately, you might need to review your application logic to ensure proper handling of data storage and retrieval, possibly implementing strategies like caching less frequently used data, setting appropriate TTLs (Time To Live), or even partitioning your data across multiple Redis instances if high memory usage persists.