Add Redis 2.6 incrbyfloat to ValueOperations

DATAREDIS-181
This commit is contained in:
Jennifer Hickey
2013-06-17 17:09:36 -07:00
parent 128360d43c
commit cc851c674e
9 changed files with 114 additions and 113 deletions

View File

@@ -42,6 +42,8 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
Long increment(long delta);
Double increment(double delta);
Integer append(String value);
Long size();

View File

@@ -52,7 +52,10 @@ class DefaultBoundValueOperations<K, V> extends DefaultBoundKeyOperations<K> imp
return ops.increment(getKey(), delta);
}
public Double increment(double delta) {
return ops.increment(getKey(), delta);
}
public Integer append(String value) {
return ops.append(getKey(), value);
}

View File

@@ -29,6 +29,7 @@ import org.springframework.data.redis.connection.RedisConnection;
* Default implementation of {@link ValueOperations}.
*
* @author Costin Leau
* @author Jennifer Hickey
*/
class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements ValueOperations<K, V> {
@@ -61,24 +62,23 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
public Long increment(K key, final long delta) {
final byte[] rawKey = rawKey(key);
// TODO add conversion service in here ?
return execute(new RedisCallback<Long>() {
public Long doInRedis(RedisConnection connection) {
if (delta == 1) {
return connection.incr(rawKey);
}
if (delta == -1) {
return connection.decr(rawKey);
}
return connection.incrBy(rawKey, delta);
}
}, true);
}
public Double increment(K key, final double delta) {
final byte[] rawKey = rawKey(key);
return execute(new RedisCallback<Double>() {
public Double doInRedis(RedisConnection connection) {
return connection.incrBy(rawKey, delta);
}
}, true);
}
public Integer append(K key, String value) {
final byte[] rawKey = rawKey(key);
final byte[] rawString = rawString(value);

View File

@@ -45,6 +45,8 @@ public interface ValueOperations<K, V> {
Long increment(K key, long delta);
Double increment(K key, double delta);
Integer append(K key, String value);
String get(K key, long start, long end);