Support lPush with multiple values
DATAREDIS-99
This commit is contained in:
@@ -505,8 +505,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Long lPush(byte[] key, byte[] value) {
|
||||
Long result = delegate.lPush(key, value);
|
||||
public Long lPush(byte[] key, byte[]... values) {
|
||||
Long result = delegate.lPush(key, values);
|
||||
if(isFutureConversion()) {
|
||||
addResultConverter(identityConverter);
|
||||
}
|
||||
@@ -1525,8 +1525,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
|
||||
}
|
||||
|
||||
|
||||
public Long lPush(String key, String value) {
|
||||
Long result = delegate.lPush(serialize(key), serialize(value));
|
||||
public Long lPush(String key, String... values) {
|
||||
Long result = delegate.lPush(serialize(key), serializeMulti(values));
|
||||
if(isFutureConversion()) {
|
||||
addResultConverter(identityConverter);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface RedisListCommands {
|
||||
|
||||
Long rPush(byte[] key, byte[] value);
|
||||
|
||||
Long lPush(byte[] key, byte[] value);
|
||||
Long lPush(byte[] key, byte[]... value);
|
||||
|
||||
Long rPushX(byte[] key, byte[] value);
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
|
||||
Long rPush(String key, String value);
|
||||
|
||||
Long lPush(String key, String value);
|
||||
Long lPush(String key, String... values);
|
||||
|
||||
Long rPushX(String key, String value);
|
||||
|
||||
|
||||
@@ -1322,17 +1322,21 @@ public class JedisConnection implements RedisConnection {
|
||||
// List commands
|
||||
//
|
||||
|
||||
public Long lPush(byte[] key, byte[] value) {
|
||||
public Long lPush(byte[] key, byte[]... values) {
|
||||
if((isPipelined() || isQueueing()) && values.length > 1) {
|
||||
throw new UnsupportedOperationException("lPush of multiple fields not supported " +
|
||||
"in pipeline or transaction");
|
||||
}
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(new JedisResult(pipeline.lpush(key, value)));
|
||||
pipeline(new JedisResult(pipeline.lpush(key, values[0])));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new JedisResult(transaction.lpush(key, value)));
|
||||
transaction(new JedisResult(transaction.lpush(key, values[0])));
|
||||
return null;
|
||||
}
|
||||
return jedis.lpush(key, value);
|
||||
return jedis.lpush(key, values);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -678,9 +678,12 @@ public class JredisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
|
||||
public Long lPush(byte[] key, byte[] value) {
|
||||
public Long lPush(byte[] key, byte[]... values) {
|
||||
if(values.length > 1) {
|
||||
throw new UnsupportedOperationException("lPush of multiple fields not supported");
|
||||
}
|
||||
try {
|
||||
jredis.lpush(key, value);
|
||||
jredis.lpush(key, values[0]);
|
||||
return null;
|
||||
} catch (Exception ex) {
|
||||
throw convertJredisAccessException(ex);
|
||||
|
||||
@@ -1421,17 +1421,17 @@ public class LettuceConnection implements RedisConnection {
|
||||
//
|
||||
|
||||
|
||||
public Long lPush(byte[] key, byte[] value) {
|
||||
public Long lPush(byte[] key, byte[]... values) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(new LettuceResult(getAsyncConnection().lpush(key, value)));
|
||||
pipeline(new LettuceResult(getAsyncConnection().lpush(key, values)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new LettuceTxResult(getConnection().lpush(key, value)));
|
||||
transaction(new LettuceTxResult(getConnection().lpush(key, values)));
|
||||
return null;
|
||||
}
|
||||
return getConnection().lpush(key, value);
|
||||
return getConnection().lpush(key, values);
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -1106,13 +1106,13 @@ public class SrpConnection implements RedisConnection {
|
||||
// List commands
|
||||
//
|
||||
|
||||
public Long lPush(byte[] key, byte[] value) {
|
||||
public Long lPush(byte[] key, byte[]... values) {
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(new SrpResult(pipeline.lpush(key, new Object[] { value })));
|
||||
pipeline(new SrpResult(pipeline.lpush(key, (Object[]) values)));
|
||||
return null;
|
||||
}
|
||||
return client.lpush(key, new Object[] { value }).data();
|
||||
return client.lpush(key, (Object[]) values ).data();
|
||||
} catch (Exception ex) {
|
||||
throw convertSrpAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -111,6 +111,15 @@ abstract class AbstractOperations<K, V> {
|
||||
return valueSerializer().serialize(value);
|
||||
}
|
||||
|
||||
byte[][] rawValues(Object... values) {
|
||||
final byte[][] rawValues = new byte[values.length][];
|
||||
int i = 0;
|
||||
for (Object value : values) {
|
||||
rawValues[i++] = rawValue(value);
|
||||
}
|
||||
return rawValues;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<HK> byte[] rawHashKey(HK hashKey) {
|
||||
Assert.notNull(hashKey, "non null hash key required");
|
||||
|
||||
@@ -35,6 +35,8 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
|
||||
|
||||
Long leftPush(V value);
|
||||
|
||||
Long leftPushAll(V... values);
|
||||
|
||||
Long leftPushIfPresent(V value);
|
||||
|
||||
Long leftPush(V pivot, V value);
|
||||
|
||||
@@ -67,6 +67,9 @@ class DefaultBoundListOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.leftPush(getKey(), value);
|
||||
}
|
||||
|
||||
public Long leftPushAll(V... values) {
|
||||
return ops.leftPushAll(getKey(), values);
|
||||
}
|
||||
|
||||
public Long leftPushIfPresent(V value) {
|
||||
return ops.leftPushIfPresent(getKey(), value);
|
||||
|
||||
@@ -76,7 +76,16 @@ class DefaultListOperations<K, V> extends AbstractOperations<K, V> implements Li
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
||||
public Long leftPushAll(K key, 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);
|
||||
|
||||
@@ -33,6 +33,8 @@ public interface ListOperations<K, V> {
|
||||
|
||||
Long leftPush(K key, V value);
|
||||
|
||||
Long leftPushAll(K key, V... values);
|
||||
|
||||
Long leftPushIfPresent(K key, V value);
|
||||
|
||||
Long leftPush(K key, V pivot, V value);
|
||||
|
||||
Reference in New Issue
Block a user