C#如何使用CacheManager设置Redis池大小?
我遇到了一个并发性高的错误:没有可用的连接来服务这个操作: 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));
});发布于 2017-11-10 08:36:09
Stackexchange.Redis不使用连接池,而是使用多路复用。
您可以通过配置 => syncTimeout更改库等待同步调用的时间(默认为1000 to )。(要在CacheManager中使用它,请使用基于连接字符串的配置或自己创建Multiplexer )。这可能会提高你的经验。
无论如何,超时和这样的连接错误大多与客户端无关,并且是由Redis服务器的单线程性质引起的,特别是当您在服务器上达到内存限制时,Redis试图删除键,或者如果Redis试图备份到磁盘.
我不能给你一个更清楚的答案,因为这些问题在很大程度上取决于您正在尝试做什么和您正在使用的Redis服务器。
您会发现关于该错误的许多其他q/a,例如,请参见StackExchange.Redis超时和“没有可用的连接来服务此操作”
https://stackoverflow.com/questions/47186753
复制相似问题