首页 新闻 会员 周边 捐助

redis连接数超出?

0
[待解决问题]
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写日志的,也就是会从线程池中调用其他线程去操作
ludi的主页 ludi | 初学一级 | 园豆:5
提问于:2018-01-09 20:48
< >
分享
所有回答(1)
0

你client不回收连接么?

Daniel Cai | 园豆:10424 (专家六级) | 2018-01-10 09:31

如何回收?

支持(0) 反对(0) ludi | 园豆:5 (初学一级) | 2018-01-10 10:12

@ludi: Dispose啊,或者这个client不要每次调用都实例化,改为单例的

支持(0) 反对(0) Daniel Cai | 园豆:10424 (专家六级) | 2018-01-10 14:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册