public static RedisClient Redis;
static CommonService()
{
Redis = new RedisClient();
}
public static dynamic RedisLock(string key, Func<dynamic> act, int spanSeconds = 20)
{
try
{
using (var client = Redis.KeyHelper.GetClient())
{
using (client.AcquireLock(key, TimeSpan.FromSeconds(spanSeconds)))
{
return act();
}
}
}
catch (Exception ex)
{
LogHelper.WriteError($"redis锁错误,key:{key}", ex);
return CommonService.GetErrorResult();
}
}
//日志(LogHelper)
public static void WriteError(string info, Exception ex)
{
if (_logExceptionEnable)
{
_logger.Error(ex, info);
}
}