DATAREDIS-288 - Polishing.
Added javadoc and assertions to ensure failing before actually sending data to redis and backed those with tests. Original pull request: #114.
This commit is contained in:
@@ -121,8 +121,16 @@ abstract class AbstractOperations<K, V> {
|
||||
return rawValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param values must not be {@literal empty} nor contain {@literal null} values.
|
||||
* @return
|
||||
* @since 1.5
|
||||
*/
|
||||
byte[][] rawValues(Collection<V> values) {
|
||||
|
||||
Assert.notEmpty(values, "Values must not be 'null' or empty.");
|
||||
Assert.noNullElements(values.toArray(), "Values must not contain 'null' value.");
|
||||
|
||||
byte[][] rawValues = new byte[values.size()][];
|
||||
int i = 0;
|
||||
for (V value : values) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Costin Leau
|
||||
* @author David Liu
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DefaultListOperations<K, V> extends AbstractOperations<K, V> implements ListOperations<K, V> {
|
||||
|
||||
@@ -86,6 +87,23 @@ class DefaultListOperations<K, V> extends AbstractOperations<K, V> implements Li
|
||||
}, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ListOperations#leftPushAll(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Long leftPushAll(K key, Collection<V> values) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[][] rawValues = rawValues(values);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.lPush(rawKey, rawValues);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
public Long leftPushIfPresent(K key, V value) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawValue = rawValue(value);
|
||||
@@ -181,6 +199,23 @@ class DefaultListOperations<K, V> extends AbstractOperations<K, V> implements Li
|
||||
}, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ListOperations#rightPushAll(java.lang.Object, java.util.Collection)
|
||||
*/
|
||||
@Override
|
||||
public Long rightPushAll(K key, Collection<V> values) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[][] rawValues = rawValues(values);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.rPush(rawKey, rawValues);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
public Long rightPushIfPresent(K key, V value) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawValue = rawValue(value);
|
||||
@@ -249,30 +284,4 @@ class DefaultListOperations<K, V> extends AbstractOperations<K, V> implements Li
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long rightPushAll(K key, Collection<V> values) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[][] rawValues = rawValues(values);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.rPush(rawKey, rawValues);
|
||||
}
|
||||
}, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long leftPushAll(K key, Collection<V> values) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[][] rawValues = rawValues(values);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.lPush(rawKey, rawValues);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* @author Costin Leau
|
||||
* @author David Liu
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface ListOperations<K, V> {
|
||||
|
||||
@@ -39,8 +40,10 @@ public interface ListOperations<K, V> {
|
||||
Long leftPushAll(K key, V... values);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param values
|
||||
* Insert all {@literal values} at the head of the list stored at {@literal key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param values must not be {@literal empty} nor contain {@literal null} values.
|
||||
* @return
|
||||
* @since 1.5
|
||||
*/
|
||||
@@ -55,8 +58,10 @@ public interface ListOperations<K, V> {
|
||||
Long rightPushAll(K key, V... values);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param values
|
||||
* Insert all {@literal values} at the tail of the list stored at {@literal key}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param values must not be {@literal empty} nor contain {@literal null} values.
|
||||
* @return
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user