Merge branch 'master' of https://gitea.nxsir.cn/nanxun/IM_NEW
This commit is contained in:
@@ -20,18 +20,40 @@ namespace FileService.Infrastructure.Storage
|
||||
public async Task SetAsync(UploadRuntimeCache upload)
|
||||
{
|
||||
string key = RedisHelper.GetUploadInfoKey(upload.UploadSessionId);
|
||||
await redis.SetAsync<UploadRuntimeCache>(key, upload);
|
||||
// 过期时间取 UploadRuntimeCache 的 ExpireAt 字段,兜底默认 24 小时
|
||||
var ttl = upload.ExpireAt > upload.CreatedAt
|
||||
? upload.ExpireAt - upload.CreatedAt
|
||||
: TimeSpan.FromHours(24);
|
||||
await redis.SetAsync<UploadRuntimeCache>(key, upload, ttl);
|
||||
|
||||
// 维护 taskId → sessionId 映射,用于 DeleteByTaskId 快速定位
|
||||
var mapKey = RedisHelper.GetUploadTaskSessionMapKey(upload.TaskId);
|
||||
await redis.SetAsync(mapKey, upload.UploadSessionId, ttl);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string sessionId)
|
||||
{
|
||||
string key = RedisHelper.GetUploadInfoKey(sessionId);
|
||||
|
||||
// 先取出缓存以清理映射 key
|
||||
var cache = await redis.GetAsync<UploadRuntimeCache>(key);
|
||||
if (cache != null)
|
||||
{
|
||||
var mapKey = RedisHelper.GetUploadTaskSessionMapKey(cache.TaskId);
|
||||
await redis.RemoveAsync(mapKey);
|
||||
}
|
||||
|
||||
await redis.RemoveAsync(key);
|
||||
}
|
||||
|
||||
public Task DeleteByTaskIdAsync(string taskId)
|
||||
public async Task DeleteByTaskIdAsync(string taskId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var mapKey = RedisHelper.GetUploadTaskSessionMapKey(taskId);
|
||||
var sessionId = await redis.GetAsync<string>(mapKey);
|
||||
if (sessionId != null)
|
||||
{
|
||||
await DeleteAsync(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<UploadRuntimeCache?> GetAsync(string sessionId)
|
||||
|
||||
Reference in New Issue
Block a user