I am using StackExchange.Redis with a replica cluster (3 nodes) configured to use Sentinel.
I get multiple requests trying to update the cache with the same data, so to avoid multiple writes, I am using When.NotExists
in StringSetAsync
. My understanding is that this will prevent the set from happening if the key already exists. I am expecting StringSetAsync
to only return true in cases where the set actually happened.
Example:
var inserted = await connectionMultiplexer.GetDatabase().StringSetAsync("my-key", "my-value", myTimeout, When.NotExists);
if(inserted == false)
{
var keyExists = await connectionMultiplexer.GetDatabase().KeyExistsAsync("my-key");
if(keyExists == false)
{
// I end up here, which I assumed should not happen.
}
}
To my surprise I am seeing that StringSetAsync
returns false even if the key didn't already exist based on the sanity check where I manually check for the existence of the key.
Notes: My environment uses 2 replica nodes and one primary. StackExchange.Redis ver: 2.1.58