Support rPush with multiple values

DATAREDIS-99
This commit is contained in:
Jennifer Hickey
2013-07-31 18:51:34 -07:00
parent 36780d14a1
commit dae047f9c5
16 changed files with 79 additions and 21 deletions

View File

@@ -645,8 +645,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return result;
}
public Long rPush(byte[] key, byte[] value) {
Long result = delegate.rPush(key, value);
public Long rPush(byte[] key, byte[]... values) {
Long result = delegate.rPush(key, values);
if(isFutureConversion()) {
addResultConverter(identityConverter);
}
@@ -1658,8 +1658,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
}
public Long rPush(String key, String value) {
Long result = delegate.rPush(serialize(key), serialize(value));
public Long rPush(String key, String... values) {
Long result = delegate.rPush(serialize(key), serializeMulti(values));
if(isFutureConversion()) {
addResultConverter(identityConverter);
}

View File

@@ -32,7 +32,7 @@ public interface RedisListCommands {
BEFORE, AFTER
}
Long rPush(byte[] key, byte[] value);
Long rPush(byte[] key, byte[]... values);
Long lPush(byte[] key, byte[]... value);

View File

@@ -125,7 +125,7 @@ public interface StringRedisConnection extends RedisConnection {
Long strLen(String key);
Long rPush(String key, String value);
Long rPush(String key, String... values);
Long lPush(String key, String... values);

View File

@@ -1343,17 +1343,21 @@ public class JedisConnection implements RedisConnection {
}
public Long rPush(byte[] key, byte[] value) {
public Long rPush(byte[] key, byte[]... values) {
if((isPipelined() || isQueueing()) && values.length > 1) {
throw new UnsupportedOperationException("rPush of multiple fields not supported " +
"in pipeline or transaction");
}
try {
if (isPipelined()) {
pipeline(new JedisResult(pipeline.rpush(key, value)));
pipeline(new JedisResult(pipeline.rpush(key, values[0])));
return null;
}
if (isQueueing()) {
transaction(new JedisResult(transaction.rpush(key, value)));
transaction(new JedisResult(transaction.rpush(key, values[0])));
return null;
}
return jedis.rpush(key, value);
return jedis.rpush(key, values);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}

View File

@@ -747,9 +747,12 @@ public class JredisConnection implements RedisConnection {
}
public Long rPush(byte[] key, byte[] value) {
public Long rPush(byte[] key, byte[]... values) {
if(values.length > 1) {
throw new UnsupportedOperationException("rPush of multiple fields not supported");
}
try {
jredis.rpush(key, value);
jredis.rpush(key, values[0]);
return null;
} catch (Exception ex) {
throw convertJredisAccessException(ex);

View File

@@ -1437,17 +1437,17 @@ public class LettuceConnection implements RedisConnection {
}
}
public Long rPush(byte[] key, byte[] value) {
public Long rPush(byte[] key, byte[]... values) {
try {
if (isPipelined()) {
pipeline(new LettuceResult(getAsyncConnection().rpush(key, value)));
pipeline(new LettuceResult(getAsyncConnection().rpush(key, values)));
return null;
}
if (isQueueing()) {
transaction(new LettuceTxResult(getConnection().rpush(key, value)));
transaction(new LettuceTxResult(getConnection().rpush(key, values)));
return null;
}
return getConnection().rpush(key, value);
return getConnection().rpush(key, values);
} catch (Exception ex) {
throw convertLettuceAccessException(ex);
}

View File

@@ -1119,13 +1119,13 @@ public class SrpConnection implements RedisConnection {
}
public Long rPush(byte[] key, byte[] value) {
public Long rPush(byte[] key, byte[]... values) {
try {
if (isPipelined()) {
pipeline(new SrpResult(pipeline.rpush(key, new Object[] { value })));
pipeline(new SrpResult(pipeline.rpush(key, (Object[]) values)));
return null;
}
return client.rpush(key, new Object[] { value }).data();
return client.rpush(key, (Object[]) values).data();
} catch (Exception ex) {
throw convertSrpAccessException(ex);
}

View File

@@ -43,6 +43,8 @@ public interface BoundListOperations<K, V> extends BoundKeyOperations<K> {
Long rightPush(V value);
Long rightPushAll(V... values);
Long rightPushIfPresent(V value);
Long rightPush(V pivot, V value);

View File

@@ -115,7 +115,10 @@ class DefaultBoundListOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.rightPush(getKey(), value);
}
public Long rightPushAll(V... values) {
return ops.rightPushAll(getKey(), values);
}
public Long rightPush(V pivot, V value) {
return ops.rightPush(getKey(), pivot, value);
}

View File

@@ -178,7 +178,16 @@ class DefaultListOperations<K, V> extends AbstractOperations<K, V> implements Li
}, true);
}
public Long rightPushAll(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.rPush(rawKey, rawValues);
}
}, true);
}
public Long rightPushIfPresent(K key, V value) {
final byte[] rawKey = rawKey(key);
final byte[] rawValue = rawValue(value);

View File

@@ -41,6 +41,8 @@ public interface ListOperations<K, V> {
Long rightPush(K key, V value);
Long rightPushAll(K key, V... values);
Long rightPushIfPresent(K key, V value);
Long rightPush(K key, V pivot, V value);