0

I try to create CacheClient object using StackExchange.Redis.Extension library. So far I know that I need two object for initialization :

_cacheClient = new StackExchangeRedisCacheClient(Serializer,ConnectionString)

Serializer and ConnectionString .

I decide to use ConfigurationOptions.ToString() to retrive connectionString for redis cache client. My problem is that I am not sure what value should be set in this class ( properties). I have following set of data from Azure cloud :

<add key="RedisHostName"  value="myapp.cache.windows.net" />
<add key="RedisPrimary"   value="UW/ESgtf[...]RZYS="/>

Question : How to mapp those two items to ConfigurationOptions class to initialize cache client object.

Radek
  • 329
  • 2
  • 17

1 Answers1

1

After some lookings over stack similar problem I found solution :

private static ConfigurationOptions _configurationOptions;

public static  ConfigurationOptions ConfigurationOptions
{
    get
    {
        return _configurationOptions ??
               (new ConfigurationOptions()
               {
                   Ssl = true,
                   EndPoints = { { ConfigurationManager.AppSettings.Get("RedisHostName")}},
                   Password  = ConfigurationManager.AppSettings.Get("RedisPrimary"),
                   DefaultVersion = new Version("2.8.5"),
                   AllowAdmin = true,
                   KeepAlive = 180
               });
    }

    set { _configurationOptions = value; }
}

Connection string is as expected

public static string `ConnectionString => ConfigurationOptions.ToString();

And CacheClient connection :

public static ICacheClient CacheClient
        {
            get { return _cacheClient ?? (_cacheClient = new StackExchangeRedisCacheClient(Serializer,ConnectionString));}

            set { _cacheClient = value; }
        }
Radek
  • 329
  • 2
  • 17