I can never store a string value to an Azure hosted Redis Cache. Using StackExchange.Redis version 2.0.601 and vs2015 and vs2019. Code below has error in comments (basically even with successful ConnectionMultiplexer.Connect there no connection is established).
static bool Connect()
{
ConnectionMultiplexer redis;
try
{
ConfigurationOptions cfgOptions = new ConfigurationOptions
{
EndPoints =
{
{"RedisOnMyAzureServer", myPort}
},
AbortOnConnectFail = false,
Ssl = true,
ConnectRetry = 3,
ConnectTimeout = 10000,
SyncTimeout = 10000,
DefaultDatabase = 0,
Password = "myPassword"
};
redis = ConnectionMultiplexer.Connect(cfgOptions); // takes 10.5 seconds on average
}
catch
{ return false; } // never errors
// some diagnostics follow
if (redis.IsConnected)
Console.WriteLine("client connection open");
else
Console.WriteLine("client connection closed");
if (redis.GetDatabase().IsConnected(default(RedisKey)))
Console.WriteLine("database connection open");
else
Console.WriteLine("database connection closed");
// both connection are always closed.
try
{
IDatabase db = redis.GetDatabase();
db.StringSet("mykey", "value");
}
catch
{ return false; } // always errors
return true;
}
Errors at last try/catch on db.StringSet method. I get this message:
No connection is available to service this operation: SET mykey; A blocking operation was interrupted by a call to WSACancelBlockingCall; IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=2,Free=1021,Min=4,Max=1023), Local-CPU: n/a
AbortOnConnectFail = false
will make the SDK ignore errors inConnectionMultiplexer.Connect
. This is why you are only seeing it forStringSet
. My guess would be that you have a network issue on the way to your VM. If you are using Azure Redis Cache (SaaS), then you should not use Endpoint/Server/Password, and instead try using the connection string.ConnectionMultiplexer.Connect(RedisCacheConnectionString)