예제 #1
0
        /// <summary>
        /// 一次写入多个key-val键值对
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        public static void SetData <T>(Dictionary <string, T> obj)
        {
            //检查非法输入
            if (obj == null || obj.Count <= 0)
            {
                return;
            }

            try
            {
                foreach (KeyValuePair <string, T> item in obj)
                {
                    RedisKey rk = item.Key.RedisProtobuf();
                    rk.Set(obj);
                }
            }
            catch (Exception ex)
            {
                string errstr = "数据写入失败,Method=SetData<T>(Dictionary<string, T> obj),内容:" + string.Join(",", obj);
                Logger.RedisLog.Error(errstr, ex);
                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// 单个对象写入(如果不存在,则先创建后写入,如果存在,则Update)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="obj"></param>
        /// <returns>true写入成功false写入失败</returns>
        public static void SetData <T>(string key, T obj)
        {
            //检查非法输入
            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }
            if (obj == null)
            {
                return;
            }

            try
            {
                RedisKey rk = key.RedisProtobuf();
                rk.Set(obj);
            }
            catch (Exception ex)
            {
                string errstr = "数据写入失败,Method=SetData<T>(string key, T obj),key=" + key + ",内容:" + obj.ToString();
                Logger.RedisLog.Error(errstr, ex);
                throw ex;
            }
        }