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*/ }
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:ServiceStack.Redis 使用链接池方法 - Python技术站