Exemplo n.º 1
0
        /// <summary>
        /// 一次获取多个键值对
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static IList <object> GetDataByKeys(Dictionary <string, Type> obj)
        {
            //检查非法输入
            if (obj == null || obj.Count <= 0)
            {
                return(null);
            }

            List <Type>   types = new List <Type>();
            List <string> keys  = new List <string>();

            try
            {
                foreach (KeyValuePair <string, Type> item in obj)
                {
                    types.Add(item.Value);
                    keys.Add(item.Key);
                }

                RedisKey rk = keys.RedisProtobuf();
                return(rk.Get(types.ToArray()));
            }
            catch (Exception ex)
            {
                string errstr = "获取数据失败,Method=GetDataByKeys(Dictionary<string,Type> obj),key=" + string.Join(",", keys);
                Logger.RedisLog.Error(errstr, ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取单个对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetData <T>(string key)
        {
            //检查非法输入
            if (string.IsNullOrWhiteSpace(key))
            {
                return(default(T));
            }

            try
            {
                RedisKey rk = key.RedisProtobuf();
                return(rk.Get <T>());
            }
            catch (Exception ex)
            {
                string errstr = "获取数据失败,Method=GetData<T>(string key),key=" + string.Join(",", key) + ",Stack=" + ex.StackTrace;
                Logger.RedisLog.Error(errstr, ex);
                throw ex;
            }
        }
Exemplo n.º 3
0
        public void GetEmployee()
        {
            RedisKey rk = "emp_1".Protobuf();

            rk.Get <Employee>();
        }