public async Task <bool> HMSet <T>(string key, IEnumerable <KeyValuePair <string, T> > keyValuePairs) { using (var cmd = factory.CreateCmd(CONST_VALURES.REDIS_COMMAND_HMSET, key)) { using (var client = await RedisClientManager.GetClient()) { foreach (var item in keyValuePairs) { cmd.Add(item.Key); cmd.AddValue(item.Value); } using (var result = await client.Send(cmd)) { if (result.Result != null) { bool ret = string.Equals(result.Result.ToString(), "OK"); return(ret); } else { return(false); } } } } }
public async Task <List <object> > HGetAll(Type type, string key) { using (var cmd = factory.CreateCmd(CONST_VALURES.REDIS_COMMAND_HGETALL, key)) { using (var client = await RedisClientManager.GetClient()) { using (var result = await client.Send(cmd)) { if (result.Results != null) { int count = result.Results.Count; List <object> results = new List <object>(count); for (int i = 1; i < count; i += 2) { results.Add(pack.UnPack(result.Results[i], type)); } return(results); } else { return(null); } } } } }
public async Task <object> HGet(Type type, string key, string field) { using (var cmd = factory.CreateCmd(CONST_VALURES.REDIS_COMMAND_HGET, key, field)) { using (var client = await RedisClientManager.GetClient()) { using (var result = await client.Send(cmd)) { if (result.Results != null) { var obj = pack.UnPack(result.Results[0], type); return(obj); } else { return(null); } } } } }
public async Task <int> HDel(string key, string field) { using (var cmd = factory.CreateCmd(CONST_VALURES.REDIS_COMMAND_HDEL, key, field)) { using (var client = await RedisClientManager.GetClient()) { using (var result = await client.Send(cmd)) { var strResult = result.Result.ToString(); if (int.TryParse(result.Result.ToString(), out int iResult)) { return(iResult); } else { throw new Exception(strResult); } } } } }
public void Dispose() { RedisClientManager.Recycle(this); }
public Redis(IPacker pack, RedisConfig config) { RedisClientManager.Init(config); this.pack = pack; this.factory = new CmdFactory(pack); }