【问题标题】:Redis - ConfigurationOptions class (StackExchange.Redis)Redis - ConfigurationOptions 类 (StackExchange.Redis)
【发布时间】:2015-12-07 00:41:05
【问题描述】:

我尝试使用 StackExchange.Redis.Extension 库创建 CacheClient 对象。 到目前为止,我知道我需要两个对象进行初始化:

_cacheClient = new StackExchangeRedisCacheClient(Serializer,ConnectionString)

序列化器和连接字符串。

我决定使用ConfigurationOptions.ToString() 来检索redis 缓存客户端的connectionString。我的问题是我不确定应该在这个类(属性)中设置什么值。 我有以下来自 Azure 云的数据集:

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

问题:如何将这两项映射到 ConfigurationOptions 类以初始化缓存客户端对象。

【问题讨论】:

    标签: azure stackexchange.redis azure-redis-cache


    【解决方案1】:

    在查看堆栈类似问题后,我找到了解决方案:

    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; }
    }
    

    连接字符串符合预期

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

    与CacheClient连接:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-16
      • 2019-09-28
      • 1970-01-01
      • 2014-06-04
      • 2016-12-03
      • 1970-01-01
      • 2020-04-20
      • 2020-01-06
      相关资源
      最近更新 更多