Trasformazione async metodi SaveSendMessages

This commit is contained in:
Samuele Locatelli
2026-06-01 08:25:28 +02:00
parent 4e632ff9f4
commit b19f21fdff
43 changed files with 70 additions and 65 deletions
+7 -7
View File
@@ -3,7 +3,7 @@ using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace MP.Data
{
@@ -44,17 +44,17 @@ namespace MP.Data
/// </summary>
/// <param name="memKey">Chiave REDIS x salvare valore</param>
/// <param name="message">Messaggio serializzato da inviare</param>
public bool saveAndSendMessage(string memKey, string message)
public async Task<bool> SaveAndSendMessageAsync(string memKey, string message)
{
bool answ = false;
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
// invio notifica tramite il canale richiesto
answ = sendMessage(message);
answ = await SendMessageAsync(message);
if (redisDb != null)
{
redisDb.StringSetAsync(memKey, message);
await redisDb.StringSetAsync(memKey, message);
}
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
@@ -68,7 +68,7 @@ namespace MP.Data
}
if (enableLog || numSent[memKey] > 30)
{
Log.Info($"saveAndSendMessage| mKey {memKey} x {numSent[memKey]} | {message.Length} size | {ts.TotalMilliseconds} ms");
Log.Info($"SaveAndSendMessageAsync| mKey {memKey} x {numSent[memKey]} | {message.Length} size | {ts.TotalMilliseconds} ms");
numSent[memKey] = 0;
}
@@ -80,7 +80,7 @@ namespace MP.Data
/// </summary>
/// <param name="newMess"></param>
/// <returns></returns>
public bool sendMessage(string newMess)
public async Task<bool> SendMessageAsync(string newMess)
{
bool answ = false;
if (!string.IsNullOrEmpty(_channel))
@@ -89,7 +89,7 @@ namespace MP.Data
ISubscriber sub = redis.GetSubscriber();
sub.Publish(_channel, newMess);
#endif
var numCli = redisSub.Publish(rChannel, newMess);
var numCli = await redisSub.PublishAsync(rChannel, newMess);
answ = numCli > 0;
}
return answ;