| | |
| | | PooledRedisClientManager prc = new PooledRedisClientManager(readWriteHosts, readOnlyHosts, |
| | | new RedisClientManagerConfig |
| | | { |
| | | MaxWritePoolSize = readWriteHosts.Length * 5, |
| | | MaxReadPoolSize = readOnlyHosts.Length * 5, |
| | | AutoStart = true, |
| | | MaxWritePoolSize = readWriteHosts.Length * 512, //最大写链接数 |
| | | MaxReadPoolSize = readOnlyHosts.Length * 512, //最大读链接数 |
| | | AutoStart = true, //自动重启 |
| | | }, i, 200, 10);// { RedisClientFactory = (IRedisClientFactory)RedisCacheClientFactory.Instance.CreateRedisClient("127.0.0.1", 6379) }; |
| | | pools.Add(i, prc); |
| | | } |
| | |
| | | /// <param name="openPooledRedis">是否开启缓冲池</param> |
| | | static RedisHelper() |
| | | { |
| | | |
| | | |
| | | //CreateManager(new string[] { "127.0.0.1:6379" }, new string[] { "127.0.0.1:6379" }); |
| | | CreateManager(new string[] { RedisIpConnString+":"+RedisPortConnString }, new string[] { RedisIpConnString + ":" + RedisPortConnString }); |
| | | Redis = prcm.GetClient() as RedisClient; |
| | | //Redis = prcm.GetClient() as RedisClient; |
| | | } |
| | | |
| | | #region Key/Value存储 |
| | |
| | | public bool Remove(string key, int db = 0) |
| | | { |
| | | Redis = (RedisClient)ChooseRedisInstance(db).GetClient(); |
| | | Redis.Dispose(); |
| | | return Redis.Remove(key); |
| | | } |
| | | |
| | |
| | | var redisList = iredisClient.Lists[listId]; |
| | | redisList.AddRange(values); |
| | | iredisClient.Save(); |
| | | Redis.Dispose(); |
| | | } |
| | | /// <summary> |
| | | /// 添加单个实体到链表中 |
| | |
| | | var redisList = iredisClient.Lists[listId]; |
| | | redisList.Add(Item); |
| | | iredisClient.Save(); |
| | | Redis.Dispose(); |
| | | } |
| | | /// <summary> |
| | | /// 获取链表 |
| | |
| | | { |
| | | Redis = (RedisClient)ChooseRedisInstance(db).GetClient(); |
| | | IRedisTypedClient<T> iredisClient = Redis.As<T>(); |
| | | Redis.Dispose(); |
| | | return iredisClient.Lists[listId]; |
| | | } |
| | | /// <summary> |
| | |
| | | var redisList = iredisClient.Lists[listId]; |
| | | redisList.RemoveValue(t); |
| | | iredisClient.Save(); |
| | | Redis.Dispose(); |
| | | } |
| | | /// <summary> |
| | | /// 根据lambada表达式删除符合条件的实体 |
| | |
| | | T value = redisList.Where(func).FirstOrDefault(); |
| | | redisList.RemoveValue(value); |
| | | iredisClient.Save(); |
| | | |
| | | Redis.Dispose(); |
| | | |
| | | } |
| | | public void test() |