Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何释放一个链接? #30

Open
zsy619 opened this issue Sep 23, 2018 · 4 comments
Open

如何释放一个链接? #30

zsy619 opened this issue Sep 23, 2018 · 4 comments

Comments

@zsy619
Copy link

zsy619 commented Sep 23, 2018

CSRedis.CSRedisClient Redis = RedisBase.RedisSentinelX;
var s1 = Redis.Increment(key1, numbers);
var s2 = Redis.Increment(key2, fees);

进行操作之后,如何释放Redis链接
来防止get connection error

@zsy619
Copy link
Author

zsy619 commented Sep 23, 2018

CSRedis.ConnectionPool.GetConnection 连接池获取超时(10秒)

@2881099
Copy link
Owner

2881099 commented Sep 23, 2018

poolsize设置多少,最好写一个接口,监控pool状态

	[HttpGet(@"connection/redis")]
	public object GetConnectionRedis() {
		var ret = new Hashtable();
		foreach(var pool in RedisHelper.ClusterNodes) {
			List<Hashtable> list = new List<Hashtable>();
			foreach (var conn in pool.Value.AllConnections) {
				list.Add(new Hashtable() {
					{ "最后活动", conn.LastActive },
					{ "获取次数", conn.UseSum }
				});
			}
			ret.Add(pool.Key, new {
				FreeConnections = pool.Value.FreeConnections.Count,
				AllConnections = pool.Value.AllConnections.Count,
				GetConnectionQueue = pool.Value.GetConnectionQueue.Count,
				GetConnectionAsyncQueue = pool.Value.GetConnectionAsyncQueue.Count,
				List = list
			});
		}
		return ret;
	}

@zsy619
Copy link
Author

zsy619 commented Sep 23, 2018

RedisHelper.ClusterNodes 这个是否为所有的节点
我这边用了5个redis库,
public static CSRedis.CSRedisClient RedisClusterX { get; set; }
public static CSRedis.CSRedisClient RedisSentinelX { get; set; }
public static CSRedis.CSRedisClient RedisCacheX { get; set; }
public static CSRedis.CSRedisClient RedisQueueX { get; set; }
public static CSRedis.CSRedisClient RedisBalanceX { get; set; }
这个方法是否能监控到这5个redis的所有链接情况

@2881099
Copy link
Owner

2881099 commented Sep 23, 2018

不是,RedisHelper有自己的CSRedisClient实例。你的这五个实例,各种有独立的连接池,循环上面我发的链接池监控

	[HttpGet(@"connection/redis")]
	public object GetConnectionRedis() {
var redisclients = new [] { 你定义的五个对象 };
var allret = new Hashtable();
foreach (var redis in redisclients) {
		var ret = new Hashtable();
		foreach(var pool in redis.ClusterNodes) {
			List<Hashtable> list = new List<Hashtable>();
			foreach (var conn in pool.Value.AllConnections) {
				list.Add(new Hashtable() {
					{ "最后活动", conn.LastActive },
					{ "获取次数", conn.UseSum }
				});
			}
			ret.Add(pool.Key, new {
				FreeConnections = pool.Value.FreeConnections.Count,
				AllConnections = pool.Value.AllConnections.Count,
				GetConnectionQueue = pool.Value.GetConnectionQueue.Count,
				GetConnectionAsyncQueue = pool.Value.GetConnectionAsyncQueue.Count,
				List = list
			});
		}
		allret.Add(1, ret);
}
    return allret;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants