Unexpected Key Expiration in Azure Redis Cache

Achala Dias 20 Reputation points
2024-11-28T03:52:46.05+00:00

Recently experienced an incident involving our Azure Redis instance where a significant number of keys expired unexpectedly during a specific timeframe. Reviewed application logs, metrics, and Redis configurations but couldn't identify a clear cause.

What could be the potential reasons for this behavior? Are there any specific Redis settings, application patterns, or external factors that might trigger key expiration?

TTL for keys: 24H

Screenshot 2024-11-21 at 4.14.03 PM

Screenshot 2024-11-21 at 4.13.48 PM

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
264 questions
{count} votes

1 answer

Sort by: Most helpful
  1. NIKHILA NETHIKUNTA 3,925 Reputation points Microsoft Vendor
    2024-11-28T06:47:32.4633333+00:00

    @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:

    1. 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. The Stats section shows the total number of expired keys. The Keyspace section provides more information about the number of keys with time-outs and the average time-out value.
    2. Key eviction: When the used_memory or used_memory_rss values in the INFO command approach the configured maxmemory 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.
    3. Maxmemory Setting: Ensure that the maxmemory setting is appropriately configured to handle your workload without triggering unnecessary evictions.
    4. 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.
    5. 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.