Init Git
This commit is contained in:
37
AMREZ.EOP.Infrastructures/UnitOfWork/RedisUnitOfWork.cs
Normal file
37
AMREZ.EOP.Infrastructures/UnitOfWork/RedisUnitOfWork.cs
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user