feat(api, core): Workload - статус формирования отчетности. RedisCacheService - получить первую запись из кэш типа Hash.
This commit is contained in:
@@ -213,6 +213,38 @@ namespace PARR.Infrastructure.Redis
|
||||
return JsonSerializer.Deserialize<T>(value);
|
||||
}
|
||||
|
||||
public async Task<(string Field, T? Value)?> GetFirstHashFieldAsync<T>(string hashKey)
|
||||
{
|
||||
logger.LogDebug("Запрос первого поля из хеша '{HashKey}'", hashKey);
|
||||
|
||||
int attempts = 0;
|
||||
int maxAttempts = 5;
|
||||
|
||||
await foreach (var entry in redis.HashScanAsync(hashKey, pageSize: 1))
|
||||
{
|
||||
if (++attempts > maxAttempts)
|
||||
{
|
||||
logger.LogWarning("Превышен лимит попыток ({Max}) для хеша '{HashKey}'", maxAttempts, hashKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (entry.Value.IsNullOrEmpty)
|
||||
{
|
||||
logger.LogDebug("Поле '{Field}' в хеше '{HashKey}' пустое, пропускаем", entry.Name, hashKey);
|
||||
continue;
|
||||
}
|
||||
|
||||
var deserialized = JsonSerializer.Deserialize<T>(entry.Value);
|
||||
|
||||
logger.LogDebug("Получено поле '{Field}' из хеша '{HashKey}', тип: {Type}", entry.Name, hashKey, typeof(T).Name);
|
||||
|
||||
return (entry.Name.ToString(), deserialized);
|
||||
}
|
||||
|
||||
logger.LogDebug("Хеш '{HashKey}' пуст или не существует", hashKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, T>> GetAllHashFieldsAsync<T>(string hashKey)
|
||||
{
|
||||
// получить все записи из Hash
|
||||
|
||||
Reference in New Issue
Block a user