private boolean tryUnlock(String id, long owner) {
        try {
            return script.eval(RScript.Mode.READ_WRITE,
                    """
                            local owner = redis.call('hget', KEYS[1], 'owner')

                            if (owner == ARGV[1]) then
                              redis.call('del', KEYS[1])
                              return true
                            end

                            return false
                            """, RScript.ReturnType.BOOLEAN, List.of(id), String.valueOf(owner));
        } catch (Throwable e) {
            log.error("Lock service failed to unlock: {}", id, e);
            return false;
        }
    }
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