Class RedisBasedLock

  • All Implemented Interfaces:
    Lock

    public class RedisBasedLock
    extends Object
    implements Lock
    Implementation of the Lock interface based on a redis database.
    Author:
    https://github.com/mcweba [Marc-Andre Weber]
    • Constructor Detail

      • RedisBasedLock

        public RedisBasedLock​(io.vertx.redis.RedisClient redisClient)
    • Method Detail

      • acquireLock

        public io.vertx.core.Future<Boolean> acquireLock​(String lock,
                                                         String token,
                                                         long lockExpiryMs)
        Description copied from interface: Lock
        Try to acquire a lock. The token parameter value must be unique across all clients and all lock requests. The lockExpiryMs parameter defines the expiry of the lock. When not manually released, the lock will be released automatically when expired.
        Specified by:
        acquireLock in interface Lock
        Parameters:
        lock - The name of the lock to acquire
        token - A unique token to define the owner of the lock
        lockExpiryMs - The lock expiry in milliseconds
        Returns:
        Returns a Future holding a Boolean value whether the lock could be successfully acquired or not
      • releaseLock

        public io.vertx.core.Future<Boolean> releaseLock​(String lock,
                                                         String token)
        Description copied from interface: Lock
        Try to release a lock. The token parameter value is used to verify that only the owner of the lock can release it. The token parameter value also prevents the original owner of an already expired lock to release a lock which has been acquired by another client.
        Specified by:
        releaseLock in interface Lock
        Parameters:
        lock - The name of the lock to release
        token - A unique token to verify if the owner of the lock tries to release the lock
        Returns:
        Returns a Future holding a Boolean value whether the lock could be sucsessfully released or not