Distributed locks are primitives that help you control access to the resource that is shared between different processes. In modern cloud-based applications processes are usually distributed between multiple physical machines.
Redis provides a great opportunities for implementing distributed locking. It’s fast (in cloud you can archive sub-millisecond response time), and it provides atomic execution guarantees for LUA scripts.
The most popular Java Redis client library that implements distributed locking algorithms is Redisson (lock docs).
Mainly Redisson lock implementations rely on Redis’s pubsub mechanism. Basically, their algorithm can be described as following: