Ejemplo n.º 1
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 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);
                 }
             }
         }
     }
 }