DATAREDIS-635 - Add keyspace scanning using Redis Cluster.
We now support SCAN commands with Redis Cluster. Cluster-wide scanning is supported with Lettuce only and SCAN on a selected node works with both clients.
// Lettuce only
Cursor<byte[]> scan = clusterConnection.scan(ScanOptions.NONE);
// Jedis and Lettuce
Cursor<byte[]> scan = clusterConnection.scan(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()), ScanOptions.NONE);
Original Pull Request: #296
This commit is contained in:
committed by
Christoph Strobl
parent
871465fa3b
commit
c18a311aa9
@@ -267,6 +267,12 @@ public interface ClusterConnectionTests {
|
||||
// DATAREDIS-315
|
||||
void keysShouldReturnAllKeysForSpecificNode();
|
||||
|
||||
// DATAREDIS-635
|
||||
void scanShouldReturnAllKeys();
|
||||
|
||||
// DATAREDIS-635
|
||||
void scanShouldReturnAllKeysForSpecificNode();
|
||||
|
||||
// DATAREDIS-315
|
||||
void lIndexShouldGetElementAtIndexCorrectly();
|
||||
|
||||
|
||||
@@ -28,16 +28,7 @@ import redis.clients.jedis.JedisPool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -46,6 +37,7 @@ import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.geo.Circle;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.GeoResults;
|
||||
@@ -972,6 +964,31 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(keysOnNode, not(hasItems(KEY_1_BYTES)));
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATAREDIS-635
|
||||
public void scanShouldReturnAllKeys() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_2);
|
||||
|
||||
clusterConnection.scan(ScanOptions.NONE);
|
||||
}
|
||||
|
||||
@Override // DATAREDIS-635
|
||||
public void scanShouldReturnAllKeysForSpecificNode() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_2);
|
||||
|
||||
Cursor<byte[]> cursor = clusterConnection.scan(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()),
|
||||
ScanOptions.NONE);
|
||||
|
||||
List<byte[]> keysOnNode = new ArrayList<>();
|
||||
cursor.forEachRemaining(keysOnNode::add);
|
||||
|
||||
assertThat(keysOnNode, hasItems(KEY_2_BYTES));
|
||||
assertThat(keysOnNode, not(hasItems(KEY_1_BYTES)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void lIndexShouldGetElementAtIndexCorrectly() {
|
||||
|
||||
|
||||
@@ -977,6 +977,34 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
|
||||
assertThat(keysOnNode, not(hasItems(KEY_1_BYTES)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-635
|
||||
public void scanShouldReturnAllKeys() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_2);
|
||||
|
||||
Cursor<byte[]> scan = clusterConnection.scan(ScanOptions.NONE);
|
||||
List<byte[]> keys = new ArrayList<>();
|
||||
scan.forEachRemaining(keys::add);
|
||||
|
||||
assertThat(keys, hasItems(KEY_1_BYTES, KEY_2_BYTES));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-635
|
||||
public void scanShouldReturnAllKeysForSpecificNode() {
|
||||
|
||||
nativeConnection.set(KEY_1, VALUE_1);
|
||||
nativeConnection.set(KEY_2, VALUE_2);
|
||||
|
||||
Cursor<byte[]> scan = clusterConnection.scan(new RedisClusterNode("127.0.0.1", 7379, SlotRange.empty()),
|
||||
ScanOptions.NONE);
|
||||
List<byte[]> keysOnNode = new ArrayList<>();
|
||||
scan.forEachRemaining(keysOnNode::add);
|
||||
|
||||
assertThat(keysOnNode, hasItems(KEY_2_BYTES));
|
||||
assertThat(keysOnNode, not(hasItems(KEY_1_BYTES)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-315
|
||||
public void lIndexShouldGetElementAtIndexCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user