Package org.redisson

Class RedissonAtomicLong

java.lang.Object
org.redisson.RedissonObject
org.redisson.RedissonAtomicLong
All Implemented Interfaces:
RAtomicLong, RAtomicLongAsync, RExpirable, RExpirableAsync, RObject, RObjectAsync

public class RedissonAtomicLong extends RedissonObject implements RAtomicLong
Distributed alternative to the AtomicLong
Author:
Nikita Koksharov
  • Constructor Details

  • Method Details

    • addAndGet

      public long addAndGet(long delta)
      Description copied from interface: RAtomicLong
      Atomically adds the given value to the current value.
      Specified by:
      addAndGet in interface RAtomicLong
      Parameters:
      delta - the value to add
      Returns:
      the updated value
    • addAndGetAsync

      public RFuture<Long> addAndGetAsync(long delta)
      Description copied from interface: RAtomicLongAsync
      Atomically adds the given value to the current value.
      Specified by:
      addAndGetAsync in interface RAtomicLongAsync
      Parameters:
      delta - the value to add
      Returns:
      the updated value
    • compareAndSet

      public boolean compareAndSet(long expect, long update)
      Description copied from interface: RAtomicLong
      Atomically sets the value to the given updated value only if the current value == the expected value.
      Specified by:
      compareAndSet in interface RAtomicLong
      Parameters:
      expect - the expected value
      update - the new value
      Returns:
      true if successful; or false if the actual value was not equal to the expected value.
    • compareAndSetAsync

      public RFuture<Boolean> compareAndSetAsync(long expect, long update)
      Description copied from interface: RAtomicLongAsync
      Atomically sets the value to the given updated value only if the current value == the expected value.
      Specified by:
      compareAndSetAsync in interface RAtomicLongAsync
      Parameters:
      expect - the expected value
      update - the new value
      Returns:
      true if successful; or false if the actual value was not equal to the expected value.
    • getAndDelete

      public long getAndDelete()
      Description copied from interface: RAtomicLong
      Gets and deletes object
      Specified by:
      getAndDelete in interface RAtomicLong
      Returns:
      the current value
    • getAndDeleteAsync

      public RFuture<Long> getAndDeleteAsync()
      Description copied from interface: RAtomicLongAsync
      Returns and deletes object
      Specified by:
      getAndDeleteAsync in interface RAtomicLongAsync
      Returns:
      the current value
    • decrementAndGet

      public long decrementAndGet()
      Description copied from interface: RAtomicLong
      Atomically decrements the current value by one.
      Specified by:
      decrementAndGet in interface RAtomicLong
      Returns:
      the updated value
    • decrementAndGetAsync

      public RFuture<Long> decrementAndGetAsync()
      Description copied from interface: RAtomicLongAsync
      Atomically decrements the current value by one.
      Specified by:
      decrementAndGetAsync in interface RAtomicLongAsync
      Returns:
      the updated value
    • get

      public long get()
      Description copied from interface: RAtomicLong
      Returns current value.
      Specified by:
      get in interface RAtomicLong
      Returns:
      the current value
    • getAsync

      public RFuture<Long> getAsync()
      Description copied from interface: RAtomicLongAsync
      Returns current value.
      Specified by:
      getAsync in interface RAtomicLongAsync
      Returns:
      the current value
    • getAndAdd

      public long getAndAdd(long delta)
      Description copied from interface: RAtomicLong
      Atomically adds the given value to the current value.
      Specified by:
      getAndAdd in interface RAtomicLong
      Parameters:
      delta - the value to add
      Returns:
      the old value before the add
    • getAndAddAsync

      public RFuture<Long> getAndAddAsync(long delta)
      Description copied from interface: RAtomicLongAsync
      Atomically adds the given value to the current value.
      Specified by:
      getAndAddAsync in interface RAtomicLongAsync
      Parameters:
      delta - the value to add
      Returns:
      the old value before the add
    • getAndSet

      public long getAndSet(long newValue)
      Description copied from interface: RAtomicLong
      Atomically sets the given value and returns the old value.
      Specified by:
      getAndSet in interface RAtomicLong
      Parameters:
      newValue - the new value
      Returns:
      the old value
    • getAndSetAsync

      public RFuture<Long> getAndSetAsync(long newValue)
      Description copied from interface: RAtomicLongAsync
      Atomically sets the given value and returns the old value.
      Specified by:
      getAndSetAsync in interface RAtomicLongAsync
      Parameters:
      newValue - the new value
      Returns:
      the old value
    • incrementAndGet

      public long incrementAndGet()
      Description copied from interface: RAtomicLong
      Atomically increments the current value by one.
      Specified by:
      incrementAndGet in interface RAtomicLong
      Returns:
      the updated value
    • incrementAndGetAsync

      public RFuture<Long> incrementAndGetAsync()
      Description copied from interface: RAtomicLongAsync
      Atomically increments the current value by one.
      Specified by:
      incrementAndGetAsync in interface RAtomicLongAsync
      Returns:
      the updated value
    • getAndIncrement

      public long getAndIncrement()
      Description copied from interface: RAtomicLong
      Atomically increments the current value by one.
      Specified by:
      getAndIncrement in interface RAtomicLong
      Returns:
      the old value
    • getAndIncrementAsync

      public RFuture<Long> getAndIncrementAsync()
      Description copied from interface: RAtomicLongAsync
      Atomically increments the current value by one.
      Specified by:
      getAndIncrementAsync in interface RAtomicLongAsync
      Returns:
      the old value
    • getAndDecrement

      public long getAndDecrement()
      Description copied from interface: RAtomicLong
      Atomically decrements by one the current value.
      Specified by:
      getAndDecrement in interface RAtomicLong
      Returns:
      the previous value
    • getAndDecrementAsync

      public RFuture<Long> getAndDecrementAsync()
      Description copied from interface: RAtomicLongAsync
      Atomically decrements by one the current value.
      Specified by:
      getAndDecrementAsync in interface RAtomicLongAsync
      Returns:
      the previous value
    • set

      public void set(long newValue)
      Description copied from interface: RAtomicLong
      Atomically sets the given value.
      Specified by:
      set in interface RAtomicLong
      Parameters:
      newValue - the new value
    • setAsync

      public RFuture<Void> setAsync(long newValue)
      Description copied from interface: RAtomicLongAsync
      Atomically sets the given value.
      Specified by:
      setAsync in interface RAtomicLongAsync
      Parameters:
      newValue - the new value
      Returns:
      void
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addListener

      public int addListener(ObjectListener listener)
      Description copied from interface: RObject
      Adds object event listener
      Specified by:
      addListener in interface RAtomicLong
      Specified by:
      addListener in interface RObject
      Overrides:
      addListener in class RedissonObject
      Parameters:
      listener - - object event listener
      Returns:
      listener id
      See Also:
    • addListenerAsync

      public RFuture<Integer> addListenerAsync(ObjectListener listener)
      Description copied from interface: RObjectAsync
      Adds object event listener
      Specified by:
      addListenerAsync in interface RAtomicLongAsync
      Specified by:
      addListenerAsync in interface RObjectAsync
      Overrides:
      addListenerAsync in class RedissonObject
      Parameters:
      listener - - object event listener
      Returns:
      listener id
      See Also:
    • removeListener

      public void removeListener(int listenerId)
      Description copied from interface: RObject
      Removes object event listener
      Specified by:
      removeListener in interface RObject
      Overrides:
      removeListener in class RedissonObject
      Parameters:
      listenerId - - listener id
    • removeListenerAsync

      public RFuture<Void> removeListenerAsync(int listenerId)
      Description copied from interface: RObjectAsync
      Removes object event listener
      Specified by:
      removeListenerAsync in interface RObjectAsync
      Overrides:
      removeListenerAsync in class RedissonObject
      Parameters:
      listenerId - - listener id
    • expire

      public boolean expire(long timeToLive, TimeUnit timeUnit)
      Description copied from interface: RExpirable
      Specified by:
      expire in interface RExpirable
      Parameters:
      timeToLive - - timeout before object will be deleted
      timeUnit - - timeout time unit
      Returns:
      true if the timeout was set and false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit)
      Description copied from interface: RExpirableAsync
      Specified by:
      expireAsync in interface RExpirableAsync
      Parameters:
      timeToLive - - timeout before object will be deleted
      timeUnit - - timeout time unit
      Returns:
      true if the timeout was set and false if not
    • expireAt

      public boolean expireAt(long timestamp)
      Description copied from interface: RExpirable
      Specified by:
      expireAt in interface RExpirable
      Parameters:
      timestamp - - expire date in milliseconds (Unix timestamp)
      Returns:
      true if the timeout was set and false if not
    • expireAtAsync

      public RFuture<Boolean> expireAtAsync(long timestamp)
      Description copied from interface: RExpirableAsync
      Specified by:
      expireAtAsync in interface RExpirableAsync
      Parameters:
      timestamp - - expire date in milliseconds (Unix timestamp)
      Returns:
      true if the timeout was set and false if not
    • expire

      public boolean expire(Instant instant)
      Description copied from interface: RExpirable
      Sets an expiration date for this object. When expire date comes the key will automatically be deleted.
      Specified by:
      expire in interface RExpirable
      Parameters:
      instant - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfSet

      public boolean expireIfSet(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSet in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfSetAsync

      public RFuture<Boolean> expireIfSetAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it has been already set. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSetAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSet

      public boolean expireIfNotSet(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSet in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSetAsync

      public RFuture<Boolean> expireIfNotSetAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it hasn't been set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSetAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfGreater

      public boolean expireIfGreater(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreater in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfGreaterAsync

      public RFuture<Boolean> expireIfGreaterAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it's greater than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreaterAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfLess

      public boolean expireIfLess(Instant time)
      Description copied from interface: RExpirable
      Sets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLess in interface RExpirable
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfLessAsync

      public RFuture<Boolean> expireIfLessAsync(Instant time)
      Description copied from interface: RExpirableAsync
      Sets an expiration date for this object only if it's less than expiration date set before. When expire date comes the object will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLessAsync in interface RExpirableAsync
      Parameters:
      time - expire date
      Returns:
      true if the timeout was set and false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(Instant instant)
      Description copied from interface: RExpirableAsync
      Set an expire date for object. When expire date comes the key will automatically be deleted.
      Specified by:
      expireAsync in interface RExpirableAsync
      Parameters:
      instant - - expire date
      Returns:
      true if the timeout was set and false if not
    • expire

      public boolean expire(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object. After the timeout has expired, the key will automatically be deleted.
      Specified by:
      expire in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireAsync

      public RFuture<Boolean> expireAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Set a timeout for object. After the timeout has expired, the key will automatically be deleted.
      Specified by:
      expireAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireAt

      public boolean expireAt(Date timestamp)
      Description copied from interface: RExpirable
      Specified by:
      expireAt in interface RExpirable
      Parameters:
      timestamp - - expire date
      Returns:
      true if the timeout was set and false if not
    • expireAtAsync

      public RFuture<Boolean> expireAtAsync(Date timestamp)
      Description copied from interface: RExpirableAsync
      Specified by:
      expireAtAsync in interface RExpirableAsync
      Parameters:
      timestamp - - expire date
      Returns:
      true if the timeout was set and false if not
    • expireIfSet

      public boolean expireIfSet(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSet in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfSetAsync

      public RFuture<Boolean> expireIfSetAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it has been already set. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfSetAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSet

      public boolean expireIfNotSet(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSet in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfNotSetAsync

      public RFuture<Boolean> expireIfNotSetAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it hasn't been set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfNotSetAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfGreater

      public boolean expireIfGreater(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreater in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfGreaterAsync

      public RFuture<Boolean> expireIfGreaterAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it's greater than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfGreaterAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfLess

      public boolean expireIfLess(Duration duration)
      Description copied from interface: RExpirable
      Sets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLess in interface RExpirable
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • expireIfLessAsync

      public RFuture<Boolean> expireIfLessAsync(Duration duration)
      Description copied from interface: RExpirableAsync
      Sets a timeout for this object only if it's less than timeout set before. After the timeout has expired, the key will automatically be deleted.

      Requires Redis 7.0.0 and higher.

      Specified by:
      expireIfLessAsync in interface RExpirableAsync
      Parameters:
      duration - timeout before object will be deleted
      Returns:
      true if the timeout was set and false if not
    • clearExpire

      public boolean clearExpire()
      Description copied from interface: RExpirable
      Clear an expire timeout or expire date for object.
      Specified by:
      clearExpire in interface RExpirable
      Returns:
      true if timeout was removed false if object does not exist or does not have an associated timeout
    • clearExpireAsync

      public RFuture<Boolean> clearExpireAsync()
      Description copied from interface: RExpirableAsync
      Clear an expire timeout or expire date for object in async mode. Object will not be deleted.
      Specified by:
      clearExpireAsync in interface RExpirableAsync
      Returns:
      true if the timeout was cleared and false if not
    • remainTimeToLive

      public long remainTimeToLive()
      Description copied from interface: RExpirable
      Returns remaining time of the object in milliseconds.
      Specified by:
      remainTimeToLive in interface RExpirable
      Returns:
      time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
    • remainTimeToLiveAsync

      public RFuture<Long> remainTimeToLiveAsync()
      Description copied from interface: RExpirableAsync
      Returns remaining time of the object in milliseconds.
      Specified by:
      remainTimeToLiveAsync in interface RExpirableAsync
      Returns:
      time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expire.
    • getExpireTime

      public long getExpireTime()
      Description copied from interface: RExpirable
      Returns expiration time of the object as the absolute Unix expiration timestamp in milliseconds.

      Requires Redis 7.0.0 and higher.

      Specified by:
      getExpireTime in interface RExpirable
      Returns:
      Unix time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expiration time.
    • getExpireTimeAsync

      public RFuture<Long> getExpireTimeAsync()
      Description copied from interface: RExpirableAsync
      Returns expiration time of the object as the absolute Unix expiration timestamp in milliseconds.

      Requires Redis 7.0.0 and higher.

      Specified by:
      getExpireTimeAsync in interface RExpirableAsync
      Returns:
      Unix time in milliseconds -2 if the key does not exist. -1 if the key exists but has no associated expiration time.
    • expireAsync

      protected RFuture<Boolean> expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys)
    • expireAtAsync

      protected RFuture<Boolean> expireAtAsync(long timestamp, String param, String... keys)
    • clearExpireAsync

      protected RFuture<Boolean> clearExpireAsync(String... keys)