Support sRem with multiple values

DATAREDIS-99
This commit is contained in:
Jennifer Hickey
2013-08-01 13:35:14 -07:00
parent d4377b4d17
commit 4020f9d97d
21 changed files with 88 additions and 42 deletions

View File

@@ -813,8 +813,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return results;
}
public Boolean sRem(byte[] key, byte[] value) {
Boolean result = delegate.sRem(key, value);
public Long sRem(byte[] key, byte[]... values) {
Long result = delegate.sRem(key, values);
if(isFutureConversion()) {
addResultConverter(identityConverter);
}
@@ -1829,8 +1829,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection {
return byteListToStringList.convert(results);
}
public Boolean sRem(String key, String value) {
Boolean result = delegate.sRem(serialize(key), serialize(value));
public Long sRem(String key, String... values) {
Long result = delegate.sRem(serialize(key), serializeMulti(values));
if(isFutureConversion()) {
addResultConverter(identityConverter);
}

View File

@@ -28,7 +28,7 @@ public interface RedisSetCommands {
Long sAdd(byte[] key, byte[]... values);
Boolean sRem(byte[] key, byte[] value);
Long sRem(byte[] key, byte[]... values);
byte[] sPop(byte[] key);

View File

@@ -161,7 +161,7 @@ public interface StringRedisConnection extends RedisConnection {
Long sAdd(String key, String... values);
Boolean sRem(String key, String value);
Long sRem(String key, String... values);
String sPop(String key);

View File

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

View File

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

View File

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

View File

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

View File

@@ -67,7 +67,7 @@ public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
List<V> randomMembers(long count);
Boolean remove(Object o);
Long remove(Object... values);
V pop();

View File

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

View File

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

View File

@@ -65,7 +65,7 @@ public interface SetOperations<K, V> {
List<V> randomMembers(K key, long count);
Boolean remove(K key, Object o);
Long remove(K key, Object... values);
V pop(K key);

View File

@@ -170,9 +170,9 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
public boolean remove(Object o) {
Boolean result = boundSetOps.remove(o);
Long result = boundSetOps.remove(o);
checkResult(result);
return result;
return result == 1;
}