This commit is contained in:
Thanakarn Klangkasame
2025-09-30 11:01:02 +07:00
commit 92e614674c
182 changed files with 9596 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
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<IDatabase>();
_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;
}