using ServiceStack.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BP.Difference.Redis { public class RedisManager { /// /// redis配置文件信息 /// private static readonly RedisConfigInfo RedisConfigInfo = RedisConfigInfo.GetConfig(); private static PooledRedisClientManager _prcm; /// /// 静态构造方法,初始化链接池管理对象 /// public RedisManager() { CreateManager(); } /// /// 创建链接池管理对象 /// private void CreateManager() { var writeServerList = SplitString(RedisConfigInfo.WriteServerList, ","); var readServerList = SplitString(RedisConfigInfo.ReadServerList, ","); _prcm = new PooledRedisClientManager(writeServerList, readServerList, new RedisClientManagerConfig { MaxWritePoolSize = RedisConfigInfo.MaxWritePoolSize, MaxReadPoolSize = RedisConfigInfo.MaxReadPoolSize, AutoStart = RedisConfigInfo.AutoStart, DefaultDb = RedisConfigInfo.DefaultDb, }); } private static IEnumerable SplitString(string strSource, string split) { return strSource.Split(split.ToArray()); } /// /// 客户端缓存操作对象 /// public IRedisClient GetClient() { if (_prcm == null) { CreateManager(); } IRedisClient redisClient = _prcm.GetClient(); return redisClient; } } }