How do I troubleshoot latency issues and sporadic failures using DEL?

Last updated 22, Mar 2024

Question

How do I troubleshoot latency issues and sporadic failures using DEL?

Answer

When using DEL on large keys, it is possible to increase the latency when the target is a huge key. Sporadic failures can be observed.

Exception information: Exception type: RedisConnectionException Exception message: SocketFailure on DEL at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server) at StackExchange.Redis.RedisDatabase.KeyDelete(RedisKey key, CommandFlags flags) at Costco.OMS.Common.UtilityLibrary.Cache.RedisCache.ClearSession(String sessionId) at Costco.OMS.Web.UI.Global.Session_Start(Object sender, EventArgs e) at System.Web.SessionState.SessionStateModule.CompleteAcquireState() at System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Try replacing DEL with UNLINK, This command is very similar to DEL: it removes the specified keys. Just like DEL, a key is ignored if it does not exist. However, the command performs the actual memory reclaiming in a different thread, so it is not blocking, while DEL is. This is where the command name comes from: the command just unlinks the keys from the keyspace. The actual removal will happen later asynchronously.