ok scrittura su redi
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SMGen.Core
|
||||
{
|
||||
//// <Auto-Generated>
|
||||
//// This is here so CodeMaid doesn't reorganize this document
|
||||
//// </Auto-Generated>
|
||||
///
|
||||
public class Constants
|
||||
{
|
||||
|
||||
public static readonly string BASE_HASH = "SMGEN";
|
||||
public static readonly string BASE_PATH = Directory.GetCurrentDirectory();
|
||||
|
||||
public const string redisBaseAddr = "SMGEN";
|
||||
public const string rKeyFiles = $"{redisBaseAddr}:Files";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace SMGen.Core
|
||||
{
|
||||
public class Enum
|
||||
{
|
||||
public enum LEVELS
|
||||
{
|
||||
LIVELLO_INGRESSI = 1,
|
||||
LIVELLO_TRANSIZIONI = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,14 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using SMGen.Core;
|
||||
using SMGen.UI;
|
||||
using SMGen.Data.Controllers;
|
||||
using SMGen.Data.DbModels;
|
||||
using StackExchange.Redis;
|
||||
using System.Diagnostics;
|
||||
using SMGen.UI.Data;
|
||||
|
||||
namespace SMGen.Data.Services
|
||||
{
|
||||
@@ -40,12 +45,12 @@ namespace SMGen.Data.Services
|
||||
|
||||
private Random rnd = new Random();
|
||||
|
||||
public SMGDataService(IConfiguration configuration)
|
||||
public SMGDataService(IConfiguration configuration, IConnectionMultiplexer redisConnMult)
|
||||
{
|
||||
_configuration = configuration;
|
||||
// Conf cache
|
||||
//redisConn = redisConnMult;
|
||||
//redisDb = this.redisConn.GetDatabase();
|
||||
redisConn = redisConnMult;
|
||||
redisDb = this.redisConn.GetDatabase();
|
||||
|
||||
// json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/
|
||||
JSSettings = new JsonSerializerSettings()
|
||||
@@ -82,6 +87,23 @@ namespace SMGen.Data.Services
|
||||
var dbResult = await dbController.AnagEventinInsert(newEvList);
|
||||
return dbResult;
|
||||
}
|
||||
public async Task<bool> FilesLoadRedis(List<FilesClass> filesList)
|
||||
{
|
||||
bool fatto = false;
|
||||
string currKey = $"{Constants.rKeyFiles}";
|
||||
Stopwatch stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
string? rawData = await redisDb.StringGetAsync(currKey);
|
||||
if (string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
rawData = JsonConvert.SerializeObject(filesList, JSSettings);
|
||||
fatto = await redisDb.StringSetAsync(currKey, rawData, LongCache);
|
||||
}
|
||||
stopWatch.Stop();
|
||||
TimeSpan ts = stopWatch.Elapsed;
|
||||
Log.Debug($"FilesLoad | REDIS in: {ts.TotalMilliseconds} ms");
|
||||
return fatto;
|
||||
}
|
||||
|
||||
|
||||
#region Private Properties
|
||||
|
||||
Reference in New Issue
Block a user