Fix procedura di flux dati:
- aggiunta conn tipo admin - tolta cancellazione intero DB - ricerca x pattern delle sole chaivi interessate
This commit is contained in:
@@ -20,6 +20,7 @@ namespace MP.SPEC.Data
|
||||
|
||||
// setup compoenti REDIS
|
||||
redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis"));
|
||||
redisConnAdmin = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("RedisAdmin"));
|
||||
redisDb = redisConn.GetDatabase();
|
||||
|
||||
// leggo cache lungo periodo
|
||||
@@ -223,8 +224,6 @@ namespace MP.SPEC.Data
|
||||
return answ;
|
||||
}
|
||||
|
||||
private int redisLongTimeCache = 5;
|
||||
|
||||
public async Task<List<ConfigModel>> ConfigGetAll()
|
||||
{
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
@@ -304,6 +303,27 @@ namespace MP.SPEC.Data
|
||||
return Task.FromResult(dbController.ElencoLink());
|
||||
}
|
||||
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
await Task.Delay(1);
|
||||
bool answ = false;
|
||||
var listEndpoints = redisConnAdmin.GetEndPoints();
|
||||
var server = redisConnAdmin.GetServer(listEndpoints[0]);
|
||||
RedisValue pattern = new RedisValue($"{redisBaseAddr}*");
|
||||
if (server != null)
|
||||
{
|
||||
var keyList = server.Keys(redisDb.Database, pattern);
|
||||
foreach (var item in keyList)
|
||||
{
|
||||
await redisDb.KeyDeleteAsync(item);
|
||||
}
|
||||
// brutalmente rimuovo intero contenuto DB... DANGER
|
||||
//await server.FlushDatabaseAsync();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco ultimi n record flux log dato macchina e flusso (ordinato x data registrazione)
|
||||
/// </summary>
|
||||
@@ -497,19 +517,6 @@ namespace MP.SPEC.Data
|
||||
return await dbController.PODLUpdateRecord(currRec);
|
||||
}
|
||||
|
||||
public async Task<bool> FlushRedisCache()
|
||||
{
|
||||
bool answ = false;
|
||||
var server = redisConn.GetServer("localhost");
|
||||
//await Task.Delay(1);
|
||||
if (server != null)
|
||||
{
|
||||
await server.FlushDatabaseAsync();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#region Protected Fields
|
||||
@@ -535,16 +542,15 @@ namespace MP.SPEC.Data
|
||||
|
||||
#region Private Fields
|
||||
|
||||
private const string redisConfKey = "MP:SPEC:Cache:Config";
|
||||
private const string redisFluxByMac = "MP:SPEC:Cache:FluxByMac";
|
||||
private const string redisMacByFlux = "MP:SPEC:Cache:MacByFlux";
|
||||
private const string redisMacList = "MP:SPEC:Cache:MacList";
|
||||
private const string redisStatoCom = "MP:SPEC:Cache:StatoCom";
|
||||
private const string redisTipoArt = "MP:SPEC:Cache:TipoArt";
|
||||
private const string redisBaseAddr = "MP:";
|
||||
private const string redisConfKey = redisBaseAddr + "SPEC:Cache:Config";
|
||||
private const string redisFluxByMac = redisBaseAddr + "SPEC:Cache:FluxByMac";
|
||||
private const string redisMacByFlux = redisBaseAddr + "SPEC:Cache:MacByFlux";
|
||||
private const string redisMacList = redisBaseAddr + "SPEC:Cache:MacList";
|
||||
private const string redisStatoCom = redisBaseAddr + "SPEC:Cache:StatoCom";
|
||||
private const string redisTipoArt = redisBaseAddr + "SPEC:Cache:TipoArt";
|
||||
private static IConfiguration _configuration = null!;
|
||||
|
||||
private static ILogger<MpDataService> _logger = null!;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
/// <summary>
|
||||
@@ -552,11 +558,18 @@ namespace MP.SPEC.Data
|
||||
/// </summary>
|
||||
private ConnectionMultiplexer redisConn = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto per connessione a REDIS modalità admin (ex flux dati)
|
||||
/// </summary>
|
||||
private ConnectionMultiplexer redisConnAdmin = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Oggetto DB redis da impiegare x chiamate R/W
|
||||
/// </summary>
|
||||
private IDatabase redisDb = null!;
|
||||
|
||||
private int redisLongTimeCache = 5;
|
||||
|
||||
#endregion Private Fields
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user