Support scan in RedisTemplate.

Closes #2260
Original pull request: #2263.
This commit is contained in:
Chen Li
2022-02-17 13:57:31 +08:00
committed by Mark Paluch
parent 31cc3bda6a
commit 04165fb747
3 changed files with 38 additions and 0 deletions

View File

@@ -62,6 +62,7 @@ import org.springframework.data.redis.test.util.CollectionAwareComparator;
* @author Mark Paluch
* @author ihaohong
* @author Hendrik Duerkop
* @author Chen Li
*/
@MethodSource("testParams")
public class RedisTemplateIntegrationTests<K, V> {
@@ -126,6 +127,22 @@ public class RedisTemplateIntegrationTests<K, V> {
assertThat(redisTemplate.keys(keyPattern)).isNotNull();
}
@ParameterizedRedisTest // GH-2260
void testScan() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeThat(key1 instanceof String || key1 instanceof byte[]).isTrue();
redisTemplate.opsForValue().set(key1, value1);
Cursor<K> cursor = redisTemplate.scan(ScanOptions.scanOptions().count(1).build());
long count = 0;
while (cursor.hasNext()) {
assertThat(cursor.next()).isEqualTo(key1);
count++;
}
cursor.close();
assertThat(count).isEqualTo(1);
}
@SuppressWarnings("rawtypes")
@ParameterizedRedisTest
void testTemplateNotInitialized() throws Exception {