private List<ProgressRecord>? ProgressRecords { get; set; }
private class ProgressRecord
{
public string Name;
public int Total;
public int Encoded;
}
PeriodicTimer periodicTimer = new(TimeSpan.FromSeconds(10));
protected override void OnInitialized()
{
UpdateProgress();
RunTimer(); // fire-and-forget
}
async void RunTimer()
{
while (await periodicTimer.WaitForNextTickAsync())
{
await InvokeAsync(() =>
{
UpdateProgress();
StateHasChanged();
});
}
}
public void Dispose()
{
MyLogger.LogError("Disposed");
periodicTimer?.Dispose();
}
private void UpdateProgress()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("redis");
ProgressRecords = new List<ProgressRecord>();
IDatabase db = redis.GetDatabase();
var endpoints = redis.GetEndPoints();
var s = redis.GetServer(endpoints[0]);
var keys = s.Keys(pattern: "*").ToArray();
foreach (var key in keys)
{
MyLogger.LogInfo($"Data found! {key}");
var hashFields = db.HashGetAll(key);
var encoded = (int)hashFields[0].Value;
var total = (int)hashFields[1].Value;
ProgressRecords.Add(new ProgressRecord { Name = key, Total = total, Encoded = encoded });
}
}