2

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

3
  • 2
    Please edit your question and include the error details. Commented Feb 22, 2020 at 2:27
  • Hi Gaurav. I added error that happens at db.StringSet("mykey", "value"); Thanks
    – mad moe
    Commented Feb 22, 2020 at 13:43
  • AbortOnConnectFail = false will make the SDK ignore errors in ConnectionMultiplexer.Connect. This is why you are only seeing it for StringSet. 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)
    – Alex
    Commented Feb 23, 2020 at 20:38

1 Answer 1

10

I got same error when I set minimum TLS version to 1.2 on Azure Redis Cache, and it was caused by TLS mismatch. It was resolved by following measures.

  • Add sslprotocols=tls12 to the connection string
  • Add TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 to TLS cipher suites

Here is the details, Remove TLS 1.0 and 1.1 from use with Azure Cache for Redis

1
  • 3
    <add key="CacheConnection" value="server:port,password=pwd,ssl=True,abortConnect=False,sslprotocols=tls12" /> Added above key in web.config and it worked
    – Sagar
    Commented Oct 25, 2020 at 14:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.