/// <summary> /// 获取所有可用活动 /// </summary> /// <returns></returns> public static async Task <List <T_Activity_xhrModel> > GetAllActivityAsync(int pageIndex, int pageSize) { using (var hashClient = CacheHelper.CreateHashClient("GetAllActivity", ActivityCacheExpiration)) { IEnumerable <T_Activity_xhrModel> xhrActivity; var getresult = hashClient.GetAsync <IEnumerable <T_Activity_xhrModel> >("GetAllActivityAsync/" + pageIndex.ToString()); if (!getresult.Result.Success) { Logger.Warn($"查询redis数据失败GetActivity:{"GetAllActivityAsync/" + pageIndex.ToString()};Error:{getresult.Result.Message}", getresult.Exception); return(null); } else { if (getresult.Result.Value.Any() && getresult.Result.Value != null) { xhrActivity = getresult.Result.Value; } else { var result = DalActivity.GetAllActivityAsync(pageIndex, pageSize); var dic = new Dictionary <string, object>(); dic.Add("GetAllActivityAsync" + pageIndex.ToString(), result.Result); IReadOnlyDictionary <string, object> roDic = new ReadOnlyDictionary <string, object>(dic); var setResult = await hashClient.SetAsync <IEnumerable <T_Activity_xhrModel> >(roDic); if (setResult.Success) { xhrActivity = result.Result; } else { Logger.Warn($"存储redis数据失败SetActivity:{"GetAllActivityAsync/" + pageIndex.ToString()};Error:{setResult.Message}", setResult.Exception); return(null); } } } if (xhrActivity != null && xhrActivity.Any()) { return(xhrActivity.Where(_ => _.StartTime <= DateTime.Now && _.EndTime > DateTime.Now)?.ToList() ?? new List <T_Activity_xhrModel>()); } return(null); } }