Beispiel #1
0
 /// <summary>
 /// 将一个值从key的表尾取出
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="client"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static T ListRightPop <T>(this IDatabase client, string key)
 {
     try
     {
         return(ProtobufHelper.DeSerialize <T>((String)client.ListRightPop(key)));
     }
     catch
     {
         return(default(T));
     }
 }
Beispiel #2
0
 /// <summary>
 /// 获取单个key value
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static T Get <T>(this IDatabase client, string key)
 {
     try
     {
         var result = client.StringGetAsync(key).Result;
         if (!result.IsNullOrEmpty)
         {
             return(ProtobufHelper.DeSerialize <T>(result));
         }
         return(default(T));
     }
     catch
     {
         return(default(T));
     }
 }
Beispiel #3
0
        public static async Task <T> GetAsync <T>(this IDatabase client, string key)
        {
            var response = default(T);

            try
            {
                var result = await client.StringGetAsync(key);

                if (!result.IsNullOrEmpty)
                {
                    response = ProtobufHelper.DeSerialize <T>(result);
                }
                return(response);
            }
            catch
            {
                return(response);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 返回列表key中指定区间内的元素,区间以偏移量start和stop指定。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="client"></param>
 /// <param name="key"></param>
 /// <param name="start"></param>
 /// <param name="stop"></param>
 /// <returns></returns>
 public static IEnumerable <T> ListRange <T>(this IDatabase client, string key, Int64 start = 0, Int64 stop = -1)
 {
     try
     {
         var list   = new List <T>();
         var values = client.ListRangeAsync(key, start, stop).Result;
         if (values == null)
         {
             return(null);
         }
         foreach (var item in values)
         {
             list.Add(ProtobufHelper.DeSerialize <T>(item));
         }
         return(list);
     }
     catch
     {
         return(null);
     }
 }
Beispiel #5
0
 /// <summary>
 /// 返回集合的所有数据
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static IEnumerable <T> SetMembers <T>(this IDatabase client, string key)
 {
     try
     {
         var values = client.SetMembersAsync(key).Result;
         if (values == null)
         {
             return(null);
         }
         var list = new List <T>();
         foreach (var item in values)
         {
             list.Add(ProtobufHelper.DeSerialize <T>((string)item));
         }
         return(list);
     }
     catch
     {
         return(null);
     }
 }