Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article explains how to diagnose actual or perceived data loss that can occur in Azure Managed Redis.
Note
Some troubleshooting steps in this guide include instructions to run Redis commands and monitor performance metrics. For more information, see the articles in Related content.
Partial loss of keys
Azure Managed Redis doesn't randomly delete keys after storing them in memory. It removes keys because of expiration policies, eviction policies, or explicit key deletion commands. Run these commands by using the CLI. Keys written to the primary node in an Azure Managed Redis instance might not be available on a replica right away. Data replicates from the primary to the replica asynchronously and in a nonblocking manner.
If keys disappear from your cache, check the following possible causes:
Cause | Description |
---|---|
Key expiration | Keys are removed because of timeouts set on them. |
Key eviction | Keys are removed when memory is low. |
Key deletion | Clients remove keys by running explicit delete commands. |
Async replication | Keys aren't available on a replica because of data replication delays. |
Key expiration
Azure Managed Redis removes a key automatically when the timeout for that key passes. For more information about Redis key expiration, see the EXPIRE command documentation. You can also set timeout values by using the SET, SETEX, GETSET, and other *STORE commands.
To see how many keys expired, use the INFO command. The Stats
section shows the total number of expired keys. The Keyspace
section gives more information about the number of keys with timeouts and the average timeout value.
# Stats
expired_keys:46583
# Keyspace
db0:keys=3450,expires=2,avg_ttl=91861015336
Check the diagnostic metrics for your cache to see if there's a correlation between when the key went missing and a spike in evicted keys.
Key eviction
Azure Managed Redis needs memory space to store data. It removes keys to free up memory when needed. When the used_memory or used_memory_rss values in the INFO command approach the configured maxmemory setting, Azure Managed Redis starts evicting keys from memory based on cache policy.
Monitor the number of evicted keys by using the INFO command:
# Stats
evicted_keys:13224
Key deletion
Redis clients run the DEL or HDEL command to remove keys from Azure Managed Redis. Track the number of delete operations by using the INFO command. If DEL or HDEL commands ran, they're listed in the Commandstats
section.
# Commandstats
cmdstat_del:calls=2,usec=90,usec_per_call=45.00
cmdstat_hdel:calls=1,usec=47,usec_per_call=47.00
Async replication
When you enable high availability in Azure Managed Redis, the service creates a primary node and at least one replica. The system copies data from the primary to the replica asynchronously using a background process. See the Redis replication documentation for more details.
Because replication isn't instantaneous, you might experience partial data loss if clients write to Redis frequently. For example, if the primary node fails after a client writes a key but before the background process replicates it, the key is lost when the replica becomes the new primary.
Major or complete loss of keys
If most or all keys disappear from your cache, check these possible causes:
Cause | Description |
---|---|
Key flushing | Someone purged the keys manually. |
Redis instance failure | The Redis server isn't available. |
Key flushing
Clients can call the FLUSHDB or FLUSHALL command to remove all keys from the Redis instance. To check if keys are flushed, use the INFO command. The Commandstats
section shows if either FLUSH
command runs:
# Commandstats
cmdstat_flushall:calls=2,usec=112,usec_per_call=56.00
cmdstat_flushdb:calls=1,usec=110,usec_per_call=52.00
Redis instance failure
Redis is an in-memory data store. Data stays on the physical or virtual machines (VM) that host the Redis cache. Azure Managed Redis caches offer high resiliency against data loss by providing zone resilient caches by default. When the primary shard in this cache fails, the replica shard automatically takes over to serve data. These VMs are in separate domains for faults and updates, which minimizes the chance of both becoming unavailable at the same time. If a major data center outage happens, the VMs can still go down together. In these rare cases, you lose your data.
Use Redis data persistence and geo-replication to better protect your data against these infrastructure failures.