Ejemplo n.º 1
0
        //更新集合
        public static bool SetUpdate <T>(string key, T oldValue, T newValue, string sql, string user, string HospitalID, string tableName)
        {
            bool b = false;

            if (RedisWriteHelper.KeyExists(key))
            {
                try
                {
                    var result = RedisWriteHelper.SetRemoveAsync(key, JsonSerializer.SerializeToString(oldValue));
                    if (result.Result)
                    {
                        var isSuccess = RedisWriteHelper.SetAddAsync(key, JsonSerializer.SerializeToString(newValue));
                        if (isSuccess.Result)
                        {
                            //BsMsgRecord msgRecord = new BsMsgRecord() { HospitalID = Convert.ToInt32(HospitalID), tableName = tableName, cacheKey = key, oldValue = JsonSerializer.SerializeToString(oldValue), newValue = JsonSerializer.SerializeToString(newValue), curUser = user, sqlRecord = sql, updateTime = DateTime.Now.ToString("yyyyMMddhhmmss") };
                            //Producer.Topic(ExchangeName, Routingkey, msgRecord);//发消息
                        }
                        b = isSuccess.Result;
                    }
                }
                catch (Exception)
                {
                    RedisWriteHelper.SetRemove(key, JsonSerializer.SerializeToString(newValue));
                    RedisWriteHelper.SetAdd(key, JsonSerializer.SerializeToString(oldValue));
                    return(false);
                }
            }
            return(b);
        }
Ejemplo n.º 2
0
 public static bool SetUpdate(string key, string guid, string value)
 {
     lock (lockObj)
     {
         bool b = false;
         try
         {
             List <object> list = RedisReadExHelper.SetSearch(key, 0, "\"GUID\":\"" + guid + "\"", 1000000);
             if (list.Count > 0)
             {
                 //var result = RedisWriteHelper.SetRemoveAsync(key, value);
                 b = RedisWriteHelper.SetRemove(key, list[0].ToString());
                 ///Task<bool>  result = RedisWriteHelper.SetRemoveAsync(key, list[0].ToString());
                 if (b)
                 {
                     var isSuccess = RedisWriteHelper.SetAdd(key, value);
                     b = isSuccess;
                 }
             }
             else
             {
                 var isSuccess = RedisWriteHelper.SetAddAsync(key, value);
                 b = isSuccess.Result;
             }
         }
         catch (Exception ex)
         {
             LogHelper.ErrorLog(string.Format("SetUpdate失败,key:{0},guid:{1},错误信息:{2}", key, guid, ex.ToString()));
         }
         return(b);
     }
 }
Ejemplo n.º 3
0
 //添加到集合
 public static bool SetAdd(string key, string guid, string value)
 {
     lock (lockObj)
     {
         bool b = false;
         try
         {
             //var result = RedisWriteHelper.SetAddAsync(key, JsonSerializer.SerializeToString(value));
             var result = RedisWriteHelper.SetAdd(key, value);
             b = result;
         }
         catch (Exception ex)
         {
             LogHelper.ErrorLog(string.Format("SetAdd失败,key:{0},guid:{1},错误信息:{2}", key, guid, ex.ToString()));
         }
         return(b);
     }
 }