Ejemplo n.º 1
0
        //private RedisClient db = null;

        //public Client(string connectName)
        //{
        //    try
        //    {
        //        db = new RedisClient(connectName);
        //    }
        //    catch(Exception ex)
        //    {
        //        string logstr = "Redis客户端初始化错误,请检查配置参数是否正确!";
        //        Logger.RedisLog.Fatal(logstr, ex);
        //        throw new Exception(logstr, ex);
        //    }
        //}


        #region 数据写入

        /// <summary>
        /// 列表数据写入(如果列表不存在,则先创建,如果存在,则Append)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="obj"></param>
        public static void SetDataList <T>(string key, IList <T> obj)
        {
            //检查非法输入
            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }
            if (obj == null || obj.Count <= 0)
            {
                return;
            }


            try
            {
                RedisKey rk = key.RedisProtobuf();
                foreach (T item in obj)
                {
                    rk.LstPush(item);
                }
            }
            catch (Exception ex)
            {
                string errstr = "数据写入失败,Method=SetDataList<T>(string key, IList<T> obj),key=" + key + ",内容:" + string.Join(",", obj);
                Logger.RedisLog.Error(errstr, ex);
                throw ex;
            }
        }