internal static ValueTask <RedisLock> CreateAsync(IRedisClientAsync redisClient, string key, TimeSpan?timeOut = default, CancellationToken token = default) { var obj = new RedisLock(redisClient, key); return(obj.AcquireAsync(timeOut, token).Await(obj)); }
public override LockResult TryGetDistributedLock(TimeSpan?getlockTimeOut, TimeSpan?taskrunTimeOut) { if (lockresult == LockResult.Success) { throw new DistributedLockException("检测到当前锁已获取"); } _client = DistributedLockConfig.GetRedisPoolClient(redisserver).GetClient(); /* * 阅读源码发现当其获取锁后,redis连接资源会一直占用,知道获取锁的资源释放后,连接才会跳出,可能会导致连接池资源的浪费。 */ try { this._lock = new ServiceStack.Redis.RedisLock(_client, key, getlockTimeOut); lockresult = LockResult.Success; } catch (Exception exp) { XXF.Log.ErrorLog.Write(string.Format("redis分布式尝试锁系统级别严重异常,redisserver:{0}", redisserver.NullToEmpty()), exp); lockresult = LockResult.LockSystemExceptionFailure; } return(lockresult); }