@Achala Dias
Thank you for the question and for using Microsoft Q&A platform.
As per my understanding, you are trying to find out the potential reasons for unexpected key expiration in Azure Redis Cache.
Based on the information you provided, there could be several reasons why keys expired unexpectedly in your Azure Redis instance. Here are some possible causes:
- Key expiration: Azure Cache for Redis removes a key automatically if the key is assigned a time-out and that period has passed. If you have set a TTL of 24 hours for your keys, they will expire after 24 hours. You can check how many keys have expired using the
INFO
command. TheStats
section shows the total number of expired keys. TheKeyspace
section provides more information about the number of keys with time-outs and the average time-out value. - Key eviction: When the
used_memory
orused_memory_rss
values in theINFO
command approach the configuredmaxmemory
setting, Azure Cache for Redis starts evicting keys from memory based on cache policy. This could result in keys being removed from the cache even if they have not expired. - Maxmemory Setting: Ensure that the maxmemory setting is appropriately configured to handle your workload without triggering unnecessary evictions.
- Application patterns: If your application is not accessing the keys frequently, they may expire before they are accessed again. You can consider changing the TTL value based on your application's access patterns.
- External factors: There could be external factors such as network issues or Redis instance failures that could cause keys to expire unexpectedly. If you use Redis replication, lag or a failover event might have caused a temporary misalignment of keys between the primary and replica, leading to perceived "unexpected" expirations.
This is a temporary issue and will get resolved after some time.
For more information, please refer to the below links:
https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-troubleshoot-data-loss#key-eviction
https://techcommunity.microsoft.com/blog/appsonazureblog/how-to-refresh-expired-keys-in-redis-using-azure-functions/4131084
https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-best-practices-memory-management
Hope this helps. Please let us know if you have any further questions.