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); } }
public static bool SetRemove(string key, string guid) { 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, list[0].ToString()); b = result.Result; } } catch (Exception ex) { LogHelper.ErrorLog(string.Format("SetRemoveAsync失败,key:{0},guid:{1},错误信息:{2}", key, guid, ex.ToString())); } return(b); } }