Support zRem with multiple values

DATAREDIS-99
This commit is contained in:
Jennifer Hickey
2013-08-01 18:29:29 -07:00
parent 44460dfdee
commit c318f24c13
21 changed files with 93 additions and 41 deletions

View File

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

View File

@@ -46,7 +46,7 @@ public interface RedisZSetCommands {
Long zAdd(byte[] key, Set<Tuple> tuples);
Boolean zRem(byte[] key, byte[] value);
Long zRem(byte[] key, byte[]... values);
Double zIncrBy(byte[] key, double increment, byte[] value);

View File

@@ -193,7 +193,7 @@ public interface StringRedisConnection extends RedisConnection {
Long zAdd(String key, Set<StringTuple> tuples);
Boolean zRem(String key, String value);
Long zRem(String key, String... values);
Double zIncrBy(String key, double increment, String value);

View File

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

View File

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

View File

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

View File

@@ -1775,13 +1775,13 @@ public class SrpConnection implements RedisConnection {
}
public Boolean zRem(byte[] key, byte[] value) {
public Long zRem(byte[] key, byte[]... values) {
try {
if (isPipelined()) {
pipeline(new SrpResult(pipeline.zrem(key, new Object[] { value }), SrpConverters.longToBoolean()));
pipeline(new SrpResult(pipeline.zrem(key, (Object[]) values)));
return null;
}
return SrpConverters.toBoolean(client.zrem(key, new Object[] { value }).data());
return client.zrem(key, (Object[]) values).data();
} catch (Exception ex) {
throw convertSrpAccessException(ex);
}

View File

@@ -69,7 +69,7 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
Long reverseRank(Object o);
Boolean remove(Object o);
Long remove(Object... values);
Long count(double min, double max);

View File

@@ -121,8 +121,8 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
}
public Boolean remove(Object o) {
return ops.remove(getKey(), o);
public Long remove(Object... values) {
return ops.remove(getKey(), values);
}

View File

@@ -281,14 +281,14 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
public Boolean remove(K key, Object o) {
public Long remove(K key, Object... values) {
final byte[] rawKey = rawKey(key);
final byte[] rawValue = rawValue(o);
final byte[][] rawValues = rawValues(values);
return execute(new RedisCallback<Boolean>() {
return execute(new RedisCallback<Long>() {
public Boolean doInRedis(RedisConnection connection) {
return connection.zRem(rawKey, rawValue);
public Long doInRedis(RedisConnection connection) {
return connection.zRem(rawKey, rawValues);
}
}, true);
}

View File

@@ -79,7 +79,7 @@ public interface ZSetOperations<K, V> {
Double score(K key, Object o);
Boolean remove(K key, Object o);
Long remove(K key, Object... values);
Long removeRange(K key, long start, long end);

View File

@@ -202,9 +202,9 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
public boolean remove(Object o) {
Boolean result = boundZSetOps.remove(o);
Long result = boundZSetOps.remove(o);
checkResult(result);
return result;
return result == 1;
}