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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1426,7 +1426,19 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
actual.add(connection.sRem("myset", "baz"));
|
||||
actual.add(connection.sMembers("myset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, true, false,
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 0l,
|
||||
new HashSet<String>(Collections.singletonList("bar")) }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRemMultiple() {
|
||||
actual.add(connection.sAdd("myset", "foo"));
|
||||
actual.add(connection.sAdd("myset", "bar"));
|
||||
actual.add(connection.sAdd("myset", "baz"));
|
||||
actual.add(connection.sRem("myset", "foo", "nope", "baz"));
|
||||
actual.add(connection.sMembers("myset"));
|
||||
verifyResults(
|
||||
Arrays.asList(new Object[] { 1l, 1l, 1l, 2l,
|
||||
new HashSet<String>(Collections.singletonList("bar")) }));
|
||||
}
|
||||
|
||||
|
||||
@@ -877,13 +877,13 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi
|
||||
|
||||
@Test
|
||||
public void testSRemBytes() {
|
||||
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline();
|
||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
|
||||
super.testSRemBytes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRem() {
|
||||
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline();
|
||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline();
|
||||
super.testSRem();
|
||||
}
|
||||
|
||||
|
||||
@@ -845,13 +845,13 @@ public class DefaultStringRedisConnectionPipelineTxTests extends
|
||||
|
||||
@Test
|
||||
public void testSRemBytes() {
|
||||
doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline();
|
||||
doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
|
||||
super.testSRemBytes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRem() {
|
||||
doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { true })})).when(nativeConnection).closePipeline();
|
||||
doReturn(Arrays.asList(new Object[] {Arrays.asList(new Object[] { 1l })})).when(nativeConnection).closePipeline();
|
||||
super.testSRem();
|
||||
}
|
||||
|
||||
|
||||
@@ -1052,16 +1052,16 @@ public class DefaultStringRedisConnectionTests {
|
||||
|
||||
@Test
|
||||
public void testSRemBytes() {
|
||||
doReturn(true).when(nativeConnection).sRem(fooBytes, barBytes);
|
||||
doReturn(1l).when(nativeConnection).sRem(fooBytes, barBytes);
|
||||
actual.add(connection.sRem(fooBytes, barBytes));
|
||||
verifyResults(Arrays.asList(new Object[] { true }));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRem() {
|
||||
doReturn(true).when(nativeConnection).sRem(fooBytes, barBytes);
|
||||
doReturn(1l).when(nativeConnection).sRem(fooBytes, barBytes);
|
||||
actual.add(connection.sRem(foo, bar));
|
||||
verifyResults(Arrays.asList(new Object[] { true }));
|
||||
verifyResults(Arrays.asList(new Object[] { 1l }));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -844,13 +844,13 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne
|
||||
|
||||
@Test
|
||||
public void testSRemBytes() {
|
||||
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec();
|
||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
|
||||
super.testSRemBytes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSRem() {
|
||||
doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec();
|
||||
doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec();
|
||||
super.testSRem();
|
||||
}
|
||||
|
||||
|
||||
@@ -446,4 +446,9 @@ public class JedisConnectionPipelineIntegrationTests extends
|
||||
public void testSAddMultiple() {
|
||||
super.testSAddMultiple();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testSRemMultiple() {
|
||||
super.testSRemMultiple();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,4 +382,9 @@ public class JedisConnectionTransactionIntegrationTests extends
|
||||
public void testSAddMultiple() {
|
||||
super.testSAddMultiple();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testSRemMultiple() {
|
||||
super.testSRemMultiple();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,6 +580,11 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
super.testSAddMultiple();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
public void testSRemMultiple() {
|
||||
super.testSRemMultiple();
|
||||
}
|
||||
|
||||
// Jredis returns null for rPush and lPush
|
||||
@Test
|
||||
public void testLLen() {
|
||||
|
||||
@@ -186,4 +186,17 @@ public class DefaultSetOperationsTests<K,V> {
|
||||
expected.add(v2);
|
||||
assertThat(setOps.members(key), isEqual(expected));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testRemove() {
|
||||
K key = keyFactory.instance();
|
||||
V v1 = valueFactory.instance();
|
||||
V v2 = valueFactory.instance();
|
||||
V v3 = valueFactory.instance();
|
||||
V v4 = valueFactory.instance();
|
||||
setOps.add(key,v1, v2, v3);
|
||||
assertEquals(Long.valueOf(2), setOps.remove(key, v1, v2, v4));
|
||||
assertThat(setOps.members(key), isEqual(Collections.singleton(v3)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user