public static async Task <TireActivityModel> SelectTireActivityAsync(string vehicleId, string tireSize) { using (var client = CacheHelper.CreateCacheClient(DefaultClientName)) { var result = await client.GetOrSetAsync(string.Concat("TireActivity/", vehicleId, tireSize), () => DalActivity.SelectTireActivity(vehicleId, tireSize), ActivityCacheExpiration); IEnumerable <TireActivityModel> tireActivity; if (result.Success) { tireActivity = result.Value; } else { Logger.Warn($"获取redis数据失败SelectTireActivityAsync:{string.Concat("TireActivity/", vehicleId, tireSize)};Error:{result.Message}", result.Exception); // redis查询失败查数据库 tireActivity = await DalActivity.SelectTireActivity(vehicleId, tireSize); } if (tireActivity != null && tireActivity.Any()) { return(tireActivity.FirstOrDefault(_ => _.StartTime <= DateTime.Now && _.EndTime > DateTime.Now)); } return(null); } }