/// <summary> /// 分布式锁 /// </summary> /// <param name="serviceName"></param> /// <param name="ipPort"></param> /// <param name="passwords"></param> /// <param name="type"></param> /// <param name="key"></param> /// <param name="timeout"></param> /// <param name="rolling"></param> public RedisLocker(string serviceName, string ipPort, string passwords, int type, string key, int timeout = 30 * 1000, int rolling = 50) { _redisHelper = RedisHelperBuilder.Build(serviceName, ipPort, passwords, type); if (!_redisHelper.GetRedisOperation().Lock(key, timeout, rolling)) { throw new Exception("RedisLocker申请锁已超时!"); } }
/// <summary> /// 分布式锁 /// </summary> /// <param name="redisConfig"></param> /// <param name="key"></param> /// <param name="timeout"></param> /// <param name="rolling"></param> public RedisLocker(RedisConfig redisConfig, string key, int timeout = 30 * 1000, int rolling = 50) { _redisHelper = RedisHelperBuilder.Build(redisConfig); if (!_redisHelper.GetRedisOperation().Lock(key, timeout, rolling)) { throw new Exception("RedisLocker申请锁已超时!"); } }