update value get/set operations

This commit is contained in:
Costin Leau
2011-03-16 14:49:09 +02:00
parent 79631fb6ec
commit a1a562c786
7 changed files with 32 additions and 22 deletions

View File

@@ -683,7 +683,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
}
@Override
public String getRange(String key, int start, int end) {
public String getRange(String key, long start, long end) {
return deserialize(delegate.getRange(serialize(key), start, end));
}
@@ -919,8 +919,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
}
@Override
public void setRange(String key, int start, int end) {
delegate.setRange(serialize(key), start, end);
public void setRange(String key, long offset, String value) {
delegate.setRange(serialize(key), offset, serialize(value));
}
@Override

View File

@@ -95,9 +95,9 @@ public interface StringRedisConnection extends RedisConnection {
Long append(String key, String value);
String getRange(String key, int start, int end);
String getRange(String key, long start, long end);
void setRange(String key, int start, int end);
void setRange(String key, long offset, String value);
Boolean getBit(String key, long offset);

View File

@@ -40,9 +40,9 @@ public interface BoundValueOperations<K, V> extends BoundKeyOperations<K> {
Integer append(String value);
String get(int start, int end);
String get(long start, long end);
void set(int start, int end);
void set(long offset, V value);
Long size();
}

View File

@@ -58,7 +58,7 @@ class DefaultBoundValueOperations<K, V> extends DefaultBoundKeyOperations<K> imp
}
@Override
public String get(int start, int end) {
public String get(long start, long end) {
return ops.get(getKey(), start, end);
}
@@ -78,8 +78,8 @@ class DefaultBoundValueOperations<K, V> extends DefaultBoundKeyOperations<K> imp
}
@Override
public void set(int start, int end) {
ops.set(getKey(), start, end);
public void set(long offset, V value) {
ops.set(getKey(), offset, null);
}
@Override

View File

@@ -96,7 +96,7 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
}
@Override
public String get(K key, final int start, final int end) {
public String get(K key, final long start, final long end) {
final byte[] rawKey = rawKey(key);
byte[] rawReturn = execute(new RedisCallback<byte[]>() {
@@ -217,13 +217,14 @@ class DefaultValueOperations<K, V> extends AbstractOperations<K, V> implements V
@Override
public void set(K key, final int start, final int end) {
public void set(K key, final long offset, V value) {
final byte[] rawKey = rawKey(key);
final byte[] rawValue = rawValue(value);
execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) {
connection.setRange(rawKey, start, end);
connection.setRange(rawKey, offset, rawValue);
return null;
}
}, true);

View File

@@ -223,13 +223,22 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
return execute(new RedisCallback<List<T>>() {
public List<T> doInRedis(RedisConnection connection) throws DataAccessException {
connection.openPipeline();
Object result = action.doInRedis(connection);
if (result != null) {
throw new InvalidDataAccessApiUsageException(
"Callback cannot returned a non-null value as it gets overwritten by the pipeline");
boolean pipelinedClosed = false;
try {
Object result = action.doInRedis(connection);
if (result != null) {
throw new InvalidDataAccessApiUsageException(
"Callback cannot returned a non-null value as it gets overwritten by the pipeline");
}
List<byte[]> pipeline = connection.closePipeline();
pipelinedClosed = true;
return SerializationUtils.deserialize(pipeline, resultSerializer);
} finally {
if (!pipelinedClosed) {
connection.closePipeline();
}
}
List<byte[]> pipeline = connection.closePipeline();
return SerializationUtils.deserialize(pipeline, resultSerializer);
}
});
}
@@ -377,7 +386,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
* Sets the string value serializer to be used by this template (when the arguments or return types
* are always strings). Defaults to {@link StringRedisSerializer}.
*
* @see ValueOperations#get(Object, int, int)
* @see ValueOperations#get(Object, long, long)
* @param stringSerializer The stringValueSerializer to set.
*/
public void setStringSerializer(RedisSerializer<String> stringSerializer) {

View File

@@ -47,9 +47,9 @@ public interface ValueOperations<K, V> {
Integer append(K key, String value);
String get(K key, int start, int end);
String get(K key, long start, long end);
void set(K key, int start, int end);
void set(K key, long offset, V value);
Long size(K key);