0

[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));
        });
4

1 回答 1

2

Stackexchange.Redis 不使用连接池,而是使用多路复用

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

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

我不能给你一个更明确的答案,因为这些问题高度依赖于你正在尝试做的事情和你正在使用的 Redis 服务器......

您会发现许多其他关于该错误的 q/a,例如,请参阅StackExchange.Redis 超时和“没有可用于服务此操作的连接”

于 2017-11-10T08:36:09.007 回答