public Lock lock(String key) {
        String id = id(key);
        long owner = ThreadLocalRandom.current().nextLong();
        log.debug("Thread {} acquires a lock to the resource {} with owner {}", Thread.currentThread().getName(), id, owner);
        long ttl = tryLock(id, owner);
        long interval = WAIT_MIN;

        while (ttl > 0) {
            LockSupport.parkNanos(interval);
            interval = Math.min(2 * interval, Math.min(WAIT_MAX, ttl + 1));
            ttl = tryLock(id, owner);
        }

        return () -> unlock(id, owner);
    }
Simple spin-lock implementation which works with Redis as cache. Supports volatile-* eviction policies.
storage/src/main/java/com/epam/aidial/core/storage/service/LockService.java