ServiceStack.Redis 使用链接池方法

PooledRedisClientManager

1、RedisManage.cs

public static class RedisManager
{
	private static PooledRedisClientManager _prcm;

 	static RedisManager()
	{
		CreateManager();
	}

    /// <summary>
    /// 创建链接池管理对象
    /// </summary>
 	private static void CreateManager()
	{	
		_prcm = new PooledRedisClientManager(writeServerList, readServerList,
					new RedisClientManagerConfig
					{
						/*Config*/
					});
	}
	public static IRedisClient GetClient()
	{
		if (_prcm == null)
		{
			CreateManager();
		}
		return _prcm.GetClient();
	}

	public static IRedisClient GetReadOnlyClient()
	{
		if (_prcm == null)
		{
			CreateManager();
		}
		return _prcm.GetReadOnlyClient();
	}
}

2、调用

using(var client = RedisManage.GetClient())
{
	/*content*/
}

using(var client = RedisManage.GetReadOnlyClient())
{
	/*content*/
}
posted @ 2016-11-22 10:36  大头大头灬下雨不愁  阅读(2019)  评论(0编辑  收藏  举报