Redisson 的分布式锁允许跨应用程序/服务器进行线程同步。Redisson 的锁和同步器列表包括:

  • Lock
  • FairLock
  • MultiLock
  • ReadWriteLock
  • Semaphore
  • PermitExpirableSemaphore
  • CountDownLatch

参与《DistributedSystem-Notes》中有关于分布式锁的详细讨论。

Lock,非公平锁

RLock lock = client.getLock("lock");
lock.lock();

// perform some long operations...
lock.unlock();

MultiLock

Redisson 的 RedissonMultiLock 组合了多个 RLock 对象,并将它们视为一个锁:

RLock lock1 = clientInstance1.getLock("lock1");
RLock lock2 = clientInstance2.getLock("lock2");
RLock lock3 = clientInstance3.getLock("lock3");

RedissonMultiLock lock = new RedissonMultiLock(lock1, lock2, lock3);
lock.lock();
// perform long running operation...
lock.unlock();

Fair Lock

RedLock

上一页