org.springframework.data.redis.support.atomic
Class RedisAtomicDouble

java.lang.Object
  

extended by java.lang.Number
      extended by org.springframework.data.redis.support.atomic.RedisAtomicDouble
All Implemented Interfaces:
Serializable, BoundKeyOperations<String>

public class RedisAtomicDouble
extends Number
implements Serializable, BoundKeyOperations<String>

Atomic double backed by Redis. Uses Redis atomic increment/decrement and watch/multi/exec operations for CAS operations.

See Also:
Serialized Form

Constructor Summary
RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory)
          Constructs a new RedisAtomicDouble instance.
RedisAtomicDouble(String redisCounter, RedisConnectionFactory factory, double initialValue)
          Constructs a new RedisAtomicDouble instance.
RedisAtomicDouble(String redisCounter, RedisOperations<String,Double> template)
          Constructs a new RedisAtomicDouble instance.
RedisAtomicDouble(String redisCounter, RedisOperations<String,Double> template, double initialValue)
          Constructs a new RedisAtomicDouble instance.
 
Method Summary
 double addAndGet(double delta)
          Atomically adds the given value to the current value.
 boolean compareAndSet(double expect, double update)
          Atomically sets the value to the given updated value if the current value == the expected value.
 double decrementAndGet()
          Atomically decrements by one the current value.
 double doubleValue()
           
 Boolean expire(long timeout, TimeUnit unit)
          Sets the key time-to-live/expiration.
 Boolean expireAt(Date date)
          Sets the key time-to-live/expiration.
 float floatValue()
           
 double get()
          Gets the current value.
 double getAndAdd(double delta)
          Atomically adds the given value to the current value.
 double getAndDecrement()
          Atomically decrements by one the current value.
 double getAndIncrement()
          Atomically increments by one the current value.
 double getAndSet(double newValue)
          Atomically sets to the given value and returns the old value.
 Long getExpire()
          Returns the expiration of this key.
 String getKey()
          Returns the key associated with this entity.
 DataType getType()
          Returns the associated Redis type.
 double incrementAndGet()
          Atomically increments by one the current value.
 int intValue()
           
 long longValue()
           
 Boolean persist()
          Removes the expiration (if any) of the key.
 void rename(String newKey)
          Renames the key.
 void set(double newValue)
          Sets to the given value.
 String toString()
          Returns the String representation of the current value.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RedisAtomicDouble

public RedisAtomicDouble(String redisCounter,
                         RedisConnectionFactory factory)
Constructs a new RedisAtomicDouble instance. Uses the value existing in Redis or 0 if none is found.

Parameters:
redisCounter - redis counter
factory - connection factory

RedisAtomicDouble

public RedisAtomicDouble(String redisCounter,
                         RedisConnectionFactory factory,
                         double initialValue)
Constructs a new RedisAtomicDouble instance.

Parameters:
redisCounter -
factory -
initialValue -

RedisAtomicDouble

public RedisAtomicDouble(String redisCounter,
                         RedisOperations<String,Double> template)
Constructs a new RedisAtomicDouble instance. Uses the value existing in Redis or 0 if none is found.

Parameters:
redisCounter - the redis counter
template - the template

RedisAtomicDouble

public RedisAtomicDouble(String redisCounter,
                         RedisOperations<String,Double> template,
                         double initialValue)
Constructs a new RedisAtomicDouble instance.

Parameters:
redisCounter - the redis counter
template - the template
initialValue - the initial value
Method Detail

get

public double get()
Gets the current value.

Returns:
the current value

set

public void set(double newValue)
Sets to the given value.

Parameters:
newValue - the new value

getAndSet

public double getAndSet(double newValue)
Atomically sets to the given value and returns the old value.

Parameters:
newValue - the new value
Returns:
the previous value

compareAndSet

public boolean compareAndSet(double expect,
                             double update)
Atomically sets the value to the given updated value if the current value == the expected value.

Parameters:
expect - the expected value
update - the new value
Returns:
true if successful. False return indicates that the actual value was not equal to the expected value.

getAndIncrement

public double getAndIncrement()
Atomically increments by one the current value.

Returns:
the previous value

getAndDecrement

public double getAndDecrement()
Atomically decrements by one the current value.

Returns:
the previous value

getAndAdd

public double getAndAdd(double delta)
Atomically adds the given value to the current value.

Parameters:
delta - the value to add
Returns:
the previous value

incrementAndGet

public double incrementAndGet()
Atomically increments by one the current value.

Returns:
the updated value

decrementAndGet

public double decrementAndGet()
Atomically decrements by one the current value.

Returns:
the updated value

addAndGet

public double addAndGet(double delta)
Atomically adds the given value to the current value.

Parameters:
delta - the value to add
Returns:
the updated value

toString

public String toString()
Returns the String representation of the current value.

Overrides:
toString in class Object
Returns:
the String representation of the current value.

getKey

public String getKey()
Description copied from interface: BoundKeyOperations
Returns the key associated with this entity.

Specified by:
getKey in interface BoundKeyOperations<String>
Returns:
key associated with the implementing entity

getType

public DataType getType()
Description copied from interface: BoundKeyOperations
Returns the associated Redis type.

Specified by:
getType in interface BoundKeyOperations<String>
Returns:
key type

getExpire

public Long getExpire()
Description copied from interface: BoundKeyOperations
Returns the expiration of this key.

Specified by:
getExpire in interface BoundKeyOperations<String>
Returns:
expiration value (in seconds)

expire

public Boolean expire(long timeout,
                      TimeUnit unit)
Description copied from interface: BoundKeyOperations
Sets the key time-to-live/expiration.

Specified by:
expire in interface BoundKeyOperations<String>
Parameters:
timeout - expiration value
unit - expiration unit
Returns:
true if expiration was set, false otherwise

expireAt

public Boolean expireAt(Date date)
Description copied from interface: BoundKeyOperations
Sets the key time-to-live/expiration.

Specified by:
expireAt in interface BoundKeyOperations<String>
Parameters:
date - expiration date
Returns:
true if expiration was set, false otherwise

persist

public Boolean persist()
Description copied from interface: BoundKeyOperations
Removes the expiration (if any) of the key.

Specified by:
persist in interface BoundKeyOperations<String>
Returns:
true if expiration was removed, false otherwise

rename

public void rename(String newKey)
Description copied from interface: BoundKeyOperations
Renames the key.
Note: The new name for empty collections will be propagated on add of first element.

Specified by:
rename in interface BoundKeyOperations<String>
Parameters:
newKey - new key

doubleValue

public double doubleValue()
Specified by:
doubleValue in class Number

floatValue

public float floatValue()
Specified by:
floatValue in class Number

intValue

public int intValue()
Specified by:
intValue in class Number

longValue

public long longValue()
Specified by:
longValue in class Number