类 DistributedReentrantLock

java.lang.Object
com.github.yingzhuo.turbocharger.redis.lock.DistributedReentrantLock
所有已实现的接口:
Serializable

public final class DistributedReentrantLock extends Object implements Serializable
基于Redis的可重入分布式锁
特色
  • 可重入
  • 实现了自动续期功能
从以下版本开始:
3.4.0
另请参阅:
  • 构造器详细资料

    • DistributedReentrantLock

      public DistributedReentrantLock(org.springframework.data.redis.core.RedisOperations<String,String> redisOperations, String lockKey, long ttlInSeconds)
      构造方法
      参数:
      redisOperations - RedisOperations实例,通常是 StringRedisTemplate
      lockKey - 作为锁的键
      ttlInSeconds - 锁自动过期时间(秒)
  • 方法详细资料

    • tryLock

      public boolean tryLock()
      尝试加锁
      返回:
      加锁结果
    • unlock

      public boolean unlock()
      尝试解锁
      返回:
      解锁结果
    • renewTtl

      public void renewTtl()
      开启后台线程在到期时间2/3时,重置TTL
    • getCurrentFrame

      @Nullable public LockFrame getCurrentFrame()
      获取当前重入锁的帧
      返回:
      当前重入锁的帧