缓存更新

This commit is contained in:
yanghongwei 2025-06-30 09:07:06 +08:00
parent 1d9da8d6e6
commit 6c31a6a72d
2 changed files with 13 additions and 2 deletions

View File

@ -50,7 +50,7 @@ namespace LY.App.Controllers
var positions = await _positionService.Index();
var alarmCount = await _redisService.GetOrSetAsync(RedisKeyList.index_data(),
async () => await _alarmService.IndexCount(),
TimeSpan.FromDays(1));
TimeSpan.FromSeconds(GetLeftTime()));
var weather = await _redisService.GetOrSetAsync(RedisKeyList.Index_Weather,
async () => await _weatherService.GetWeather(),
TimeSpan.FromHours(3));
@ -66,6 +66,17 @@ namespace LY.App.Controllers
return Ok(result);
}
private int GetLeftTime() {
DateTime now = DateTime.Now;
// 今天的结束时间 23:59:59
DateTime endOfDay = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
// 相差时间
TimeSpan remaining = endOfDay - now;
// 剩余秒数
return (int)remaining.TotalSeconds;
}
private async Task<List<SyncLocation>> GetUserLocation()
{
var keys = await _redisService.GetAllKeysAsync("user_locationbyid_*");

View File

@ -8,7 +8,7 @@
"log2db": true, //
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "server=114.66.57.139;port=23306;database=lyapp;user=root;password=dklymysql;Pooling=true;"
"DefaultConnection": "server=114.66.57.139;port=33306;database=lyapp;user=root;password=dklymysql;Pooling=true;"
},
"Token": {
"SecretKey": "HWLSNPM+OhlFe4wwEV/teSWsxGjrWbxKnHonxW5Z+mFlQq3zonv5",