using NetAdmin.Application.Repositories;
using NetAdmin.Domain.DbMaps.Dependency;
using StackExchange.Redis;
namespace NetAdmin.Application.Services;
///
/// Redis Service Base
///
///
/// Initializes a new instance of the class.
/// Redis Service Base
///
public abstract class RedisService(BasicRepository rpo)
: RepositoryService(rpo)
where TEntity : EntityBase //
where TPrimary : IEquatable
{
///
/// Redis Database
///
protected IDatabase RedisDatabase { get; } //
= App.GetService()
.GetDatabase(App.GetOptions().Instances.First(x => x.Name == Chars.FLG_REDIS_INSTANCE_DATA_CACHE).Database);
///
/// 获取锁
///
protected Task GetLockerAsync(string lockerName)
{
return RedisLocker.GetLockerAsync(RedisDatabase, lockerName, TimeSpan.FromSeconds(Numbers.SECS_REDIS_LOCK_EXPIRY)
, Numbers.MAX_LIMIT_RETRY_CNT_REDIS_LOCK, TimeSpan.FromSeconds(Numbers.SECS_REDIS_LOCK_RETRY_DELAY));
}
///
/// 获取锁(仅获取一次)
///
protected Task GetLockerOnceAsync(string lockerName)
{
return RedisLocker.GetLockerAsync(RedisDatabase, lockerName, TimeSpan.FromSeconds(Numbers.SECS_REDIS_LOCK_EXPIRY), 1
, TimeSpan.FromSeconds(Numbers.SECS_REDIS_LOCK_RETRY_DELAY));
}
}