using System.Data; using AMREZ.EOP.Abstractions.Applications.Tenancy; using AMREZ.EOP.Abstractions.Infrastructures.Common; using AMREZ.EOP.Abstractions.Storage; using StackExchange.Redis; namespace AMREZ.EOP.Infrastructures.UnitOfWork; public sealed class RedisUnitOfWork : IUnitOfWork { private readonly IDbScope _scope; private ITransaction? _tx; public RedisUnitOfWork(IDbScope scope) => _scope = scope; public string Backend => "redis"; public Task BeginAsync(ITenantContext tenant, IsolationLevel isolation = IsolationLevel.ReadCommitted, CancellationToken ct = default) { _scope.EnsureForTenant(tenant); var db = _scope.Get(); _tx = db.CreateTransaction(); return Task.CompletedTask; } public async Task CommitAsync(CancellationToken ct = default) { if (_tx != null) await _tx.ExecuteAsync(); } public Task RollbackAsync(CancellationToken ct = default) { _tx = null; // drop return Task.CompletedTask; } public ValueTask DisposeAsync() => ValueTask.CompletedTask; }