System.TimeoutException: Redis Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use. 在 ServiceStack.Redis.PooledRedisClientManager.GetClient()
public class RedisCache
{
private static PooledRedisClientManager RedisClient = null;
private static RedisConfig redisConfigInfo = RedisConfig.GetConfig();
static RedisCache()
{
CreateManager();
}
private static void CreateManager()
{
string[] strArray = SplitString(redisConfigInfo.WriteServerList, ",");
RedisClientManagerConfig config1 = new RedisClientManagerConfig();
config1.MaxWritePoolSize = redisConfigInfo.MaxWritePoolSize;
config1.MaxReadPoolSize = redisConfigInfo.MaxReadPoolSize;
config1.AutoStart = redisConfigInfo.AutoStart;
config1.DefaultDb = new long?((long)redisConfigInfo.DataBaseId);
RedisClient = new PooledRedisClientManager(SplitString(redisConfigInfo.ReadServerList, ","), strArray, config1);
}
public static void AddItemToList<T>(string key, T value)
{
var client = RedisClient.GetClient();
if (value.GetType() == typeof(string))
{
client.AddItemToList(key, value.ToString());
}
else
{
client.AddItemToList(key,JsonConvert.SerializeObject(value));
}
}
}
本地运行没有问题,但是到了生产环境就报上面那个错误,我是在async await异步调用redis写日志的,也就是会从线程池中调用其他线程去操作
你client不回收连接么?
如何回收?
@ludi: Dispose啊,或者这个client不要每次调用都实例化,改为单例的