DATAREDIS-313 - Overhaul SCAN, HSCAN, SSCAN, ZSCAN operations.

Unify naming and return types. Update supported commands documentation. Remove key from BoundHashOperations and use getKey() instead.

Original pull request: #81.
This commit is contained in:
Christoph Strobl
2014-06-06 07:54:23 +02:00
committed by Thomas Darimont
parent c939c8a9ff
commit d8b53a4c96
19 changed files with 58 additions and 48 deletions

View File

@@ -162,10 +162,11 @@ public interface RedisHashCommands {
/**
* Use a {@link Cursor} to iterate over entries in hash at {@code key}.
*
* @since 1.4
* @see http://redis.io/commands/scan
* @param key
* @param options
* @return
* @since 1.4
*/
Cursor<Map.Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options);
}

View File

@@ -339,10 +339,11 @@ public interface RedisZSetCommands {
/**
* Use a {@link Cursor} to iterate over elements in sorted set at {@code key}.
*
* @since 1.4
* @see http://redis.io/commands/scan
* @param key
* @param options
* @return
* @since 1.4
*/
Cursor<Tuple> zScan(byte[] key, ScanOptions options);
}

View File

@@ -320,29 +320,29 @@ public interface StringRedisConnection extends RedisConnection {
List<RedisClientInfo> getClientList();
/**
* @since 1.4
* @see RedisHashCommands#hScan(byte[], ScanOptions)
* @param key
* @param options
* @return
* @since 1.4
*/
Cursor<Map.Entry<String, String>> hScan(String key, ScanOptions options);
/**
* @since 1.4
* @see RedisSetCommands#sScan(byte[], ScanOptions)
* @param key
* @param options
* @return
* @since 1.4
*/
Cursor<String> sScan(String key, ScanOptions options);
/**
* @since 1.4
* @see RedisZSetCommands#zScan(byte[], ScanOptions)
* @param key
* @param options
* @return
* @since 1.4
*/
Cursor<StringTuple> zScan(String key, ScanOptions options);
}

View File

@@ -2910,6 +2910,10 @@ public class JedisConnection implements RedisConnection {
}
}
/**
* @since 1.4
* @return
*/
public Cursor<byte[]> scan() {
return scan(ScanOptions.NONE);
}
@@ -2928,7 +2932,6 @@ public class JedisConnection implements RedisConnection {
* @param options
* @return
*/
@SuppressWarnings("resource")
public Cursor<byte[]> scan(long cursorId, ScanOptions options) {
return new ScanCursor<byte[]>(cursorId, options) {
@@ -2960,11 +2963,11 @@ public class JedisConnection implements RedisConnection {
}
/**
* @since 1.4
* @param key
* @param cursorId
* @param options
* @return
* @since 1.4
*/
public Cursor<Tuple> zScan(byte[] key, Long cursorId, ScanOptions options) {
@@ -3022,12 +3025,23 @@ public class JedisConnection implements RedisConnection {
}.open();
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisHashCommands#hScan(byte[], org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options) {
return hscan(key, 0, options);
return hScan(key, 0, options);
}
public Cursor<Entry<byte[], byte[]>> hscan(byte[] key, long cursorId, ScanOptions options) {
/**
* @since 1.4
* @param key
* @param cursorId
* @param options
* @return
*/
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, long cursorId, ScanOptions options) {
return new KeyBoundCursor<Map.Entry<byte[], byte[]>>(key, cursorId, options) {

View File

@@ -3033,6 +3033,10 @@ public class LettuceConnection implements RedisConnection {
}
}
/**
* @since 1.4
* @return
*/
public Cursor<byte[]> scan() {
return scan(0, ScanOptions.NONE);
}
@@ -3080,17 +3084,17 @@ public class LettuceConnection implements RedisConnection {
*/
@Override
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, ScanOptions options) {
return hscan(key, 0, options);
return hScan(key, 0, options);
}
/**
* @since 1.4
* @param key
* @param cursorId
* @param options
* @return
* @since 1.4
*/
public Cursor<Entry<byte[], byte[]>> hscan(byte[] key, long cursorId, ScanOptions options) {
public Cursor<Entry<byte[], byte[]>> hScan(byte[] key, long cursorId, ScanOptions options) {
return new KeyBoundCursor<Entry<byte[], byte[]>>(key, cursorId, options) {
@@ -3165,11 +3169,11 @@ public class LettuceConnection implements RedisConnection {
}
/**
* @since 1.4
* @param key
* @param cursorId
* @param options
* @return
* @since 1.4
*/
public Cursor<Tuple> zScan(byte[] key, long cursorId, ScanOptions options) {

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -58,9 +57,9 @@ public interface BoundHashOperations<H, HK, HV> extends BoundKeyOperations<H> {
Map<HK, HV> entries();
/**
* @param key
* @since 1.4
* @param key
* @return
*/
Iterator<Map.Entry<HK, HV>> scan(H key, ScanOptions options);
Cursor<Map.Entry<HK, HV>> scan(ScanOptions options);
}

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -79,5 +78,5 @@ public interface BoundSetOperations<K, V> extends BoundKeyOperations<K> {
* @return
* @since 1.4
*/
Iterator<V> sScan(ScanOptions options);
Cursor<V> scan(ScanOptions options);
}

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
@@ -97,5 +96,5 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @return
* @since 1.4
*/
Iterator<TypedTuple<V>> scan(ScanOptions options);
Cursor<TypedTuple<V>> scan(ScanOptions options);
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -111,7 +110,7 @@ class DefaultBoundHashOperations<H, HK, HV> extends DefaultBoundKeyOperations<H>
* @see org.springframework.data.redis.core.BoundHashOperations#hscan(java.lang.Object)
*/
@Override
public Iterator<Entry<HK, HV>> scan(H key, ScanOptions options) {
return ops.scan(key, options);
public Cursor<Entry<HK, HV>> scan(ScanOptions options) {
return ops.scan(getKey(), options);
}
}

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -145,7 +144,7 @@ class DefaultBoundSetOperations<K, V> extends DefaultBoundKeyOperations<K> imple
* @see org.springframework.data.redis.core.BoundSetOperations#sScan(org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Iterator<V> sScan(ScanOptions options) {
return ops.sScan(getKey(), options);
public Cursor<V> scan(ScanOptions options) {
return ops.scan(getKey(), options);
}
}

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import org.springframework.data.redis.connection.DataType;
@@ -163,7 +162,7 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
* @see org.springframework.data.redis.core.BoundZSetOperations#scan(org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Iterator<TypedTuple<V>> scan(ScanOptions options) {
public Cursor<TypedTuple<V>> scan(ScanOptions options) {
return ops.scan(getKey(), options);
}
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -233,7 +232,7 @@ class DefaultHashOperations<K, HK, HV> extends AbstractOperations<K, Object> imp
* @see org.springframework.data.redis.core.HashOperations#hscan(java.lang.Object, org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Iterator<Entry<HK, HV>> scan(K key, final ScanOptions options) {
public Cursor<Entry<HK, HV>> scan(K key, final ScanOptions options) {
final byte[] rawKey = rawKey(key);
return execute(new RedisCallback<Cursor<Map.Entry<HK, HV>>>() {

View File

@@ -253,7 +253,7 @@ class DefaultSetOperations<K, V> extends AbstractOperations<K, V> implements Set
* @see org.springframework.data.redis.core.SetOperations#sScan(java.lang.Object, org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Cursor<V> sScan(K key, final ScanOptions options) {
public Cursor<V> scan(K key, final ScanOptions options) {
final byte[] rawKey = rawKey(key);
return execute(new RedisCallback<Cursor<V>>() {

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import org.springframework.core.convert.converter.Converter;
@@ -374,7 +373,7 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
* @see org.springframework.data.redis.core.ZSetOperations#scan(java.lang.Object, org.springframework.data.redis.core.ScanOptions)
*/
@Override
public Iterator<TypedTuple<V>> scan(K key, final ScanOptions options) {
public Cursor<TypedTuple<V>> scan(K key, final ScanOptions options) {
final byte[] rawKey = rawKey(key);
Cursor<Tuple> cursor = execute(new RedisCallback<Cursor<Tuple>>() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 the original author or authors.
* Copyright 2011-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -25,6 +24,7 @@ import java.util.Set;
* Redis map specific operations working on a hash.
*
* @author Costin Leau
* @author Christoph Strobl
*/
public interface HashOperations<H, HK, HV> {
@@ -57,10 +57,10 @@ public interface HashOperations<H, HK, HV> {
RedisOperations<H, ?> getOperations();
/**
* @param key
* @since 1.4
* @param key
* @param options
* @return
*/
Iterator<Map.Entry<HK, HV>> scan(H key, ScanOptions options);
Cursor<Map.Entry<HK, HV>> scan(H key, ScanOptions options);
}

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -78,10 +77,10 @@ public interface SetOperations<K, V> {
/**
* Iterate over elements in set at {@code key}.
*
* @since 1.4
* @param key
* @param options
* @return
* @since 1.4
*/
Iterator<V> sScan(K key, ScanOptions options);
Cursor<V> scan(K key, ScanOptions options);
}

View File

@@ -17,7 +17,6 @@
package org.springframework.data.redis.core;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
/**
@@ -110,10 +109,10 @@ public interface ZSetOperations<K, V> {
RedisOperations<K, V> getOperations();
/**
* @since 1.4
* @param key
* @param options
* @return
* @since 1.4
*/
Iterator<TypedTuple<V>> scan(K key, ScanOptions options);
Cursor<TypedTuple<V>> scan(K key, ScanOptions options);
}