Support sRem with multiple values
DATAREDIS-99
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user