diff --git a/EgwCoreLib.Lux.Data/Services/General/IRedisService.cs b/EgwCoreLib.Lux.Data/Services/General/IRedisService.cs index 42c4df75..193788a5 100644 --- a/EgwCoreLib.Lux.Data/Services/General/IRedisService.cs +++ b/EgwCoreLib.Lux.Data/Services/General/IRedisService.cs @@ -9,56 +9,204 @@ namespace EgwCoreLib.Lux.Data.Services.General { #region Public Methods + /// + /// Eliminazione chiave su cache REDIS in modalità Async + /// + /// + /// bool Delete(string key); + /// + /// Eliminazione chiave su cache REDIS in modalità Async + /// + /// + /// Task DeleteAsync(string key); + /// + /// Elimina chiavi Redis che corrispondono al pattern specificato + /// + /// Pattern di ricerca (es. "Lux:*" o "*") + /// true se eliminazione completata, false altrimenti Task FlushPatternAsync(RedisValue pattern); + /// + /// Recupero stringa da cache REDIS x key indicata in modalità Async + /// + /// + /// string? Get(string key); + /// + /// Recupero stringa da cache REDIS x key indicata in modalità Async + /// + /// + /// Task GetAsync(string key); + /// + /// Recupera un campo specifico da una hash REDIS + /// + /// Chiave della hash + /// Campo da recuperare + /// Valore del campo, o RedisValue.Null se non esiste + Task HashGetAsync(string hashKey, string field); + + /// + /// Recupera TUTTI i campi e valori da una hash REDIS + /// + /// Chiave della hash + /// Elenco completo di campi e valori, o lista vuota se non esiste + Task> HashGetAllAsync(string hashKey); + + + /// + /// Pubblicazione messaggio su channel + /// + /// + /// + /// long Publish(string channel, string message); + /// + /// Pubblicazione messaggio su channel in modalità async + /// + /// + /// + /// Task PublishAsync(string channel, string message); + /// + /// Conteggio elementi in QUEUE (FIFO) + /// + /// long QueueCount(RedisKey queueName); + /// + /// Conteggio elementi in QUEUE (FIFO) + /// + /// Task QueueCountAsync(RedisKey queueName); + /// + /// Recupero list di TUTTI i valori in QUEUE (FIFO) senza eliminare + /// + /// + /// num max di elementi da recuperare List QueueListAll(RedisKey queueName); + /// + /// Recupero list di TUTTI i valori in QUEUE (FIFO) senza eliminare + /// + /// + /// num max di elementi da recuperare Task> QueueListAllAsync(RedisKey queueName); + /// + /// Recupero valore in QUEUE (FIFO) + /// + /// RedisValue QueuePop(RedisKey queueName); + /// + /// Recupero list di TUTTI i valori in QUEUE (FIFO) eliminandoli dalla coda + /// + /// List QueuePopAll(RedisKey queueName); + /// + /// Recupero list di TUTTI i valori in QUEUE (FIFO) eliminandoli dalla coda in modo Async + /// + /// Task> QueuePopAllAsync(RedisKey queueName); + /// + /// Recupero valore in QUEUE (FIFO) Async + /// + /// Task QueuePopAsync(RedisKey queueName); + /// + /// Recupero una list di valori in QUEUE (FIFO) + /// + /// + /// num max di elementi da recuperare List QueuePopList(RedisKey queueName, int maxElem); + /// + /// Recupero una list di valori in QUEUE (FIFO) + /// + /// + /// num max di elementi da recuperare Task> QueuePopListAsync(RedisKey queueName, int maxElem); + /// + /// Scrittura valore in QUEUE (FIFO) + /// + /// + /// long QueuePush(RedisKey queueName, RedisValue value); + /// + /// Scrittura valore in QUEUE (FIFO) + /// + /// + /// Task QueuePushAsync(RedisKey queueName, RedisValue value); + /// + /// Rimuove un valore specifico dalla queue Redis (FIFO) + /// + /// Nome della lista + /// Valore da rimuovere + /// Numero di elementi rimossi long QueueRemove(RedisKey queueName, RedisValue value); + /// + /// Rimuove un valore specifico dalla queue Redis (FIFO) Async + /// + /// Nome della lista + /// Valore da rimuovere + /// Numero di elementi rimossi Task QueueRemoveAsync(RedisKey queueName, RedisValue value); + /// + /// Reset della coda + /// + /// + /// bool QueueReset(RedisKey queueName); + /// + /// Reset della coda Async + /// + /// + /// Task QueueResetAsync(RedisKey queueName); + /// + /// Scrittura string su cache REDIS in modalità Async + /// + /// + /// + /// + /// bool Set(string key, string value, TimeSpan? expiry = null); + /// + /// Scrittura string su cache REDIS in modalità Async + /// + /// + /// + /// + /// Task SetAsync(string key, string value, TimeSpan? expiry = null); + /// + /// Sottoscrizione canale REDIS + handler esecuzione + /// + /// + /// void Subscribe(string channel, Action handler); #endregion Public Methods diff --git a/EgwCoreLib.Lux.Data/Services/General/ProdService.cs b/EgwCoreLib.Lux.Data/Services/General/ProdService.cs index 6eb36941..c0278bf4 100644 --- a/EgwCoreLib.Lux.Data/Services/General/ProdService.cs +++ b/EgwCoreLib.Lux.Data/Services/General/ProdService.cs @@ -19,7 +19,6 @@ namespace EgwCoreLib.Lux.Data.Services.General { // conf redis service _redisService = redisService; - _db = _redisConn.GetDatabase(); chPub = _config.GetValue("ServerConf:ChannelPub") ?? ""; Log.Info($"ProdService | Init OK"); } @@ -300,13 +299,13 @@ namespace EgwCoreLib.Lux.Data.Services.General public async Task UpdateQueueAsync(Constants.EXECENVIRONMENTS cEnvir, string hashKey) { // recupero info accessorie da redis - var tipo = await _db.HashGetAsync(hashKey, "tipo"); + var tipo = await _redisService.HashGetAsync(hashKey, "tipo"); // verifico SE si tratta di un create/estimate e nel caso processo coda req x sistemare - if (!tipo.IsNull && !string.IsNullOrEmpty(tipo)) + if (tipo != null && !string.IsNullOrEmpty(tipo)) { string rKey = ""; - var UID = await _db.HashGetAsync(hashKey, "UID"); + var UID = await _redisService.HashGetAsync(hashKey, "UID"); var parti = ((string)tipo).Split('-'); if (parti.Length == 2) { @@ -347,7 +346,6 @@ namespace EgwCoreLib.Lux.Data.Services.General #region Private Fields private static Logger Log = LogManager.GetCurrentClassLogger(); - private readonly IDatabase _db; private readonly IRedisService _redisService; private readonly string chPub = ""; diff --git a/EgwCoreLib.Lux.Data/Services/General/RedisService.cs b/EgwCoreLib.Lux.Data/Services/General/RedisService.cs index d6fcf817..e46478eb 100644 --- a/EgwCoreLib.Lux.Data/Services/General/RedisService.cs +++ b/EgwCoreLib.Lux.Data/Services/General/RedisService.cs @@ -32,10 +32,8 @@ namespace EgwCoreLib.Lux.Data.Services.General #region Public Methods /// - /// Eliminazione chiave su cache REDIS in modalità Async + /// /// - /// - /// public bool Delete(string key) { Log.Trace($"Set request for {key}"); @@ -43,10 +41,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Eliminazione chiave su cache REDIS in modalità Async + /// /// - /// - /// public async Task DeleteAsync(string key) { Log.Trace($"SetAsync request for {key}"); @@ -54,10 +50,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Elimina chiavi Redis che corrispondono al pattern specificato + /// /// - /// Pattern di ricerca (es. "Lux:*" o "*") - /// true se eliminazione completata, false altrimenti public async Task FlushPatternAsync(RedisValue pattern) { try @@ -105,10 +99,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero stringa da cache REDIS x key indicata in modalità Async + /// /// - /// - /// public string? Get(string key) { Log.Trace($"Get request for {key}"); @@ -117,10 +109,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero stringa da cache REDIS x key indicata in modalità Async + /// /// - /// - /// public async Task GetAsync(string key) { Log.Trace($"GetAsync request for {key}"); @@ -129,11 +119,27 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Pubblicazione messaggio su channel + /// + /// + public async Task> HashGetAllAsync(string hashKey) + { + Log.Trace($"HashGetAllAsync request for {hashKey}"); + var results = await _db.HashGetAllAsync(hashKey); + return results.ToList(); + } + + /// + /// + /// + public async Task HashGetAsync(string hashKey, string field) + { + Log.Trace($"HashGetAsync request for {hashKey}.{field}"); + return await _db.HashGetAsync(hashKey, field); + } + + /// + /// /// - /// - /// - /// public long Publish(string channel, string message) { Log.Trace($"Publish: channel {channel}"); @@ -143,11 +149,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Pubblicazione messaggio su channel in modalità async + /// /// - /// - /// - /// public async Task PublishAsync(string channel, string message) { Log.Trace($"PublishAsync: channel {channel}"); @@ -157,28 +160,24 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Conteggio elementi in QUEUE (FIFO) + /// /// - /// public long QueueCount(RedisKey queueName) { return _db.ListLength(queueName); } /// - /// Conteggio elementi in QUEUE (FIFO) + /// /// - /// public async Task QueueCountAsync(RedisKey queueName) { return await _db.ListLengthAsync(queueName); } /// - /// Recupero list di TUTTI i valori in QUEUE (FIFO) senza eliminare + /// /// - /// - /// num max di elementi da recuperare public List QueueListAll(RedisKey queueName) { // lettura + reset in blocco @@ -187,10 +186,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero list di TUTTI i valori in QUEUE (FIFO) senza eliminare + /// /// - /// - /// num max di elementi da recuperare public async Task> QueueListAllAsync(RedisKey queueName) { // lettura + reset in blocco @@ -199,19 +196,16 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero valore in QUEUE (FIFO) + /// /// - /// public RedisValue QueuePop(RedisKey queueName) { return _db.ListLeftPop(queueName); } /// - /// Recupero list di TUTTI i valori in QUEUE (FIFO) eliminandoli dalla coda + /// /// - /// - /// num max di elementi da recuperare public List QueuePopAll(RedisKey queueName) { // lettura + reset in blocco @@ -224,10 +218,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero list di TUTTI i valori in QUEUE (FIFO) eliminandoli dalla coda in modo Async + /// /// - /// - /// num max di elementi da recuperare public async Task> QueuePopAllAsync(RedisKey queueName) { // lettura + reset in blocco @@ -241,19 +233,16 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero valore in QUEUE (FIFO) Async + /// /// - /// public async Task QueuePopAsync(RedisKey queueName) { return await _db.ListLeftPopAsync(queueName); } /// - /// Recupero una list di valori in QUEUE (FIFO) + /// /// - /// - /// num max di elementi da recuperare public List QueuePopList(RedisKey queueName, int maxElem) { // nuovo metodo con rimozione @@ -268,10 +257,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Recupero una list di valori in QUEUE (FIFO) + /// /// - /// - /// num max di elementi da recuperare public async Task> QueuePopListAsync(RedisKey queueName, int maxElem) { // nuovo metodo con rimozione @@ -286,10 +273,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Scrittura valore in QUEUE (FIFO) + /// /// - /// - /// public long QueuePush(RedisKey queueName, RedisValue value) { long qLen = _db.ListRightPush(queueName, value); @@ -297,10 +282,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Scrittura valore in QUEUE (FIFO) + /// /// - /// - /// public async Task QueuePushAsync(RedisKey queueName, RedisValue value) { long qLen = await _db.ListRightPushAsync(queueName, value); @@ -308,11 +291,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Rimuove un valore specifico dalla queue Redis (FIFO) + /// /// - /// Nome della lista - /// Valore da rimuovere - /// Numero di elementi rimossi public long QueueRemove(RedisKey queueName, RedisValue value) { // count = 0 → rimuove TUTTE le occorrenze del valore @@ -320,11 +300,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Rimuove un valore specifico dalla queue Redis (FIFO) + /// /// - /// Nome della lista - /// Valore da rimuovere - /// Numero di elementi rimossi public async Task QueueRemoveAsync(RedisKey queueName, RedisValue value) { // count = 0 → rimuove TUTTE le occorrenze del valore @@ -332,10 +309,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Reset della coda + /// /// - /// - /// public bool QueueReset(RedisKey queueName) { bool answ = _db.KeyDelete(queueName); @@ -343,10 +318,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Reset della coda + /// /// - /// - /// public async Task QueueResetAsync(RedisKey queueName) { bool answ = await _db.KeyDeleteAsync(queueName); @@ -354,12 +327,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Scrittura string su cache REDIS in modalità Async + /// /// - /// - /// - /// - /// public bool Set(string key, string value, TimeSpan? tsExpiry = null) { Log.Trace($"Set request for {key}"); @@ -367,12 +336,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Scrittura string su cache REDIS in modalità Async + /// /// - /// - /// - /// - /// public async Task SetAsync(string key, string value, TimeSpan? tsExpiry = null) { Log.Trace($"SetAsync request for {key}"); @@ -380,10 +345,8 @@ namespace EgwCoreLib.Lux.Data.Services.General } /// - /// Sottoscrizione canale REDIS + handler esecuzione + /// /// - /// - /// public void Subscribe(string channel, Action handler) { Log.Trace($"Subscribed to channel {channel}");