Spring Data Key-Value

org.springframework.data.keyvalue.redis.support.atomic
Class RedisAtomicLong

java.lang.Object
  extended by java.lang.Number
      extended by org.springframework.data.keyvalue.redis.support.atomic.RedisAtomicLong
All Implemented Interfaces:
Serializable, KeyBound<String>

public class RedisAtomicLong
extends Number
implements Serializable, KeyBound<String>

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

Author:
Costin Leau
See Also:
AtomicLong, Serialized Form

Constructor Summary
RedisAtomicLong(String redisCounter, RedisConnectionFactory factory)
          Constructs a new RedisAtomicLong instance.
RedisAtomicLong(String redisCounter, RedisConnectionFactory factory, long initialValue)
          Constructs a new RedisAtomicLong instance.
RedisAtomicLong(String redisCounter, RedisOperations<String,Long> operations)
          Constructs a new RedisAtomicLong instance.
RedisAtomicLong(String redisCounter, RedisOperations<String,Long> operations, long initialValue)
          Constructs a new RedisAtomicLong instance with the given initial value.
 
Method Summary
 long addAndGet(long delta)
          Atomically adds the given value to the current value.
 boolean compareAndSet(long expect, long update)
          Atomically sets the value to the given updated value if the current value == the expected value.
 long decrementAndGet()
          Atomically decrements by one the current value.
 double doubleValue()
           
 float floatValue()
           
 long get()
          Gets the current value.
 long getAndAdd(long delta)
          Atomically adds the given value to the current value.
 long getAndDecrement()
          Atomically decrements by one the current value.
 long getAndIncrement()
          Atomically increments by one the current value.
 long getAndSet(long newValue)
          Atomically sets to the given value and returns the old value.
 String getKey()
          Returns the key associated with this entity.
 long incrementAndGet()
          Atomically increments by one the current value.
 int intValue()
           
 long longValue()
           
 void set(long 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

RedisAtomicLong

public RedisAtomicLong(String redisCounter,
                       RedisConnectionFactory factory)
Constructs a new RedisAtomicLong instance.

Parameters:
redisCounter - redis counter
factory - connection factory

RedisAtomicLong

public RedisAtomicLong(String redisCounter,
                       RedisConnectionFactory factory,
                       long initialValue)
Constructs a new RedisAtomicLong instance.

Parameters:
redisCounter -
factory -
initialValue -

RedisAtomicLong

public RedisAtomicLong(String redisCounter,
                       RedisOperations<String,Long> operations)
Constructs a new RedisAtomicLong instance. Uses as initial value the data from the backing store (sets the counter to 0 if no value is found). Use RedisAtomicLong(String, RedisOperations, long) to set the counter to a certain value as an alternative constructor or set(long).

Parameters:
redisCounter -
operations -

RedisAtomicLong

public RedisAtomicLong(String redisCounter,
                       RedisOperations<String,Long> operations,
                       long initialValue)
Constructs a new RedisAtomicLong instance with the given initial value.

Parameters:
redisCounter -
operations -
initialValue -
Method Detail

getKey

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

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

get

public long get()
Gets the current value.

Returns:
the current value

set

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

Parameters:
newValue - the new value

getAndSet

public long getAndSet(long 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(long expect,
                             long 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 long getAndIncrement()
Atomically increments by one the current value.

Returns:
the previous value

getAndDecrement

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

Returns:
the previous value

getAndAdd

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

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

incrementAndGet

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

Returns:
the updated value

decrementAndGet

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

Returns:
the updated value

addAndGet

public long addAndGet(long 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.

intValue

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

longValue

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

floatValue

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

doubleValue

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

Spring Data Key-Value

Copyright © 2010-2011 SpringSource. All Rights Reserved.