DATAREDIS-647 - Include last key of SDIFF for set difference retrieval.

We now consider the last key in SDIFF command execution on Redis Cluster to correctly compute the set difference.

Original Pull Request: #250
This commit is contained in:
Mark Paluch
2017-05-11 14:15:47 +02:00
committed by Christoph Strobl
parent f4a2df8e8c
commit 98b8b66048
4 changed files with 14 additions and 8 deletions

View File

@@ -1434,7 +1434,7 @@ public class JedisClusterConnection implements RedisClusterConnection {
}
byte[] source = keys[0];
byte[][] others = Arrays.copyOfRange(keys, 1, keys.length - 1);
byte[][] others = Arrays.copyOfRange(keys, 1, keys.length);
ByteArraySet values = new ByteArraySet(sMembers(source));
Collection<Set<byte[]>> resultList = clusterCommandExecutor

View File

@@ -1197,7 +1197,7 @@ public class LettuceClusterConnection extends LettuceConnection
}
byte[] source = keys[0];
byte[][] others = Arrays.copyOfRange(keys, 1, keys.length - 1);
byte[][] others = Arrays.copyOfRange(keys, 1, keys.length);
ByteArraySet values = new ByteArraySet(sMembers(source));
Collection<Set<byte[]>> nodeResult = clusterCommandExecutor

View File

@@ -16,12 +16,17 @@
package org.springframework.data.redis.connection.jedis;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsEmptyCollection.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
@@ -57,10 +62,6 @@ import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.util.RedisClusterRule;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
/**
* @author Christoph Strobl
* @author Mark Paluch
@@ -1334,15 +1335,17 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
/**
* @see DATAREDIS-315
* @see DATAREDIS-315, DATAREDIS-647
*/
@Test
public void sDiffShouldWorkWhenKeysNotMapToSameSlot() {
nativeConnection.sadd(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES);
nativeConnection.sadd(KEY_2_BYTES, VALUE_2_BYTES, VALUE_3_BYTES);
nativeConnection.sadd(KEY_3_BYTES, VALUE_1_BYTES, VALUE_3_BYTES);
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES));
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty()));
}
/**

View File

@@ -16,6 +16,7 @@
package org.springframework.data.redis.connection.lettuce;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.collection.IsEmptyCollection.*;
import static org.hamcrest.collection.IsIterableContainingInOrder.*;
import static org.hamcrest.number.IsCloseTo.*;
import static org.junit.Assert.*;
@@ -1327,15 +1328,17 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
/**
* @see DATAREDIS-315
* @see DATAREDIS-315, DATAREDIS-647
*/
@Test
public void sDiffShouldWorkWhenKeysNotMapToSameSlot() {
nativeConnection.sadd(KEY_1, VALUE_1, VALUE_2);
nativeConnection.sadd(KEY_2, VALUE_2, VALUE_3);
nativeConnection.sadd(KEY_3, VALUE_1, VALUE_3);
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES), hasItems(VALUE_1_BYTES));
assertThat(clusterConnection.sDiff(KEY_1_BYTES, KEY_2_BYTES, KEY_3_BYTES), is(empty()));
}
/**