@Nullable
    public Lock tryLock(String key) {
        String id = id(key);
        long owner = ThreadLocalRandom.current().nextLong();
        long ttl = tryLock(id, owner);
        return (ttl == 0) ? () -> unlock(id, owner) : null;
    }
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