【问题标题】:How to set the Redis Server pool size with the CacheManager?如何使用 CacheManager 设置 Redis Server 池大小?
【发布时间】:2017-11-10 16:36:09
【问题描述】:

[C#] 如何使用 CacheManager 设置 Redis Server 池大小?

我收到一个高并发错误:没有可用的连接来服务这个操作:HMGET,如何设置连接池大小?

No connection is available to service this operation: HMGET U

 at StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor`1 processor, ServerEndPoint server)
   at StackExchange.Redis.RedisDatabase.HashGet(RedisKey key, RedisValue[] hashFields, CommandFlags flags)
   at CacheManager.Redis.RedisCacheHandle`1.<>c__DisplayClass25_0.<GetCacheItemInternal>b__0()
   at CacheManager.Redis.RetryHelper.Retry[T](Func`1 retryme, Int32 timeOut, Int32 retries)
   at CacheManager.Redis.RedisCacheHandle`1.Retry[T](Func`1 retryme)
   at CacheManager.Redis.RedisCacheHandle`1.GetCacheItemInternal(String key, String region)
   at CacheManager.Redis.RedisCacheHandle`1.GetCacheItemInternal(String key)
   at CacheManager.Core.Internal.BaseCache`1.GetCacheItem(String key)
   at CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key, String region)
   at CacheManager.Core.BaseCacheManager`1.GetCacheItemInternal(String key)
   at CacheManager.Core.Internal.BaseCache`1.GetCacheItem(String key)
   at CacheManager.Core.Internal.BaseCache`1.Get(String key)
   at CacheManager.Core.Internal.BaseCache`1.Get[TOut](String key)

========================

      var cache = CacheFactory.Build("RuntimeCache", settings =>
        {
            settings.WithSystemRuntimeCacheHandle("RuntimeCache")
            .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromMinutes(10))
            .And
            .WithRedisConfiguration("RedisCache", config =>
            {
                config.WithAllowAdmin()
                .WithDatabase(1)
                .WithPassword(password)
                .WithEndpoint(host, port);
            })
            .WithMaxRetries(100)
            .WithRetryTimeout(50)
            .WithRedisBackPlate("RedisCache")   
            .WithRedisCacheHandle("RedisCache", true)
            .WithExpiration(ExpirationMode.Sliding, TimeSpan.FromMinutes(30));
        });

【问题讨论】:

    标签: c# redis cachemanager


    【解决方案1】:

    Stackexchange.Redis 不使用连接池,而是使用multiplexing

    您可以通过configuration => syncTimeout 更改库等待同步调用的时间(默认为 1000 毫秒)。 (要将其与 CacheManager 一起使用,请使用基于连接字符串的配置或自己创建 Multiplexer)。 这可能会改善您的体验。

    无论如何,超时和此类连接错误大部分时间与客户端无关,并且是由 Redis 服务器的单线程性质引起的,尤其是当您达到服务器的内存限制并且 Redis 尝试删除键时,或者如果Redis 尝试备份到磁盘...

    我无法给您更明确的答案,因为这些问题在很大程度上取决于您尝试执行的操作以及您使用的 Redis 服务器...

    您会发现许多其他关于该错误的问题,例如见StackExchange.Redis timeout and "No connection is available to service this operation"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-21
      • 2012-06-19
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多