hvals now return a Collection, not a Set neither a List.
This commit is contained in:
@@ -3,6 +3,7 @@ package redis.clients.jedis;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -844,11 +845,11 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* @param key
|
||||
* @return All the fields values contained into a hash.
|
||||
*/
|
||||
public Set<byte[]> hvals(final byte[] key) {
|
||||
public Collection<byte[]> hvals(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.hvals(key);
|
||||
final List<byte[]> lresult = client.getBinaryMultiBulkReply();
|
||||
return new HashSet<byte[]>(lresult);
|
||||
return lresult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -62,7 +63,7 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Set<byte[]> hkeys(byte[] key);
|
||||
|
||||
Set<byte[]> hvals(byte[] key);
|
||||
Collection<byte[]> hvals(byte[] key);
|
||||
|
||||
Map<byte[], byte[]> hgetAll(byte[] key);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -169,7 +170,7 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo> implement
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public Set<byte[]> hvals(byte[] key) {
|
||||
public Collection<byte[]> hvals(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -773,11 +774,11 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* @param key
|
||||
* @return All the fields values contained into a hash.
|
||||
*/
|
||||
public Set<String> hvals(final String key) {
|
||||
public Collection<String> hvals(final String key) {
|
||||
checkIsInMulti();
|
||||
client.hvals(key);
|
||||
final List<String> lresult = client.getMultiBulkReply();
|
||||
return new HashSet<String>(lresult);
|
||||
return lresult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -60,7 +61,7 @@ public interface JedisCommands {
|
||||
|
||||
Set<String> hkeys(String key);
|
||||
|
||||
Set<String> hvals(String key);
|
||||
Collection<String> hvals(String key);
|
||||
|
||||
Map<String, String> hgetAll(String key);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -155,7 +156,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public Set<String> hvals(String key) {
|
||||
public Collection<String> hvals(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,63 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
jedis.get("foo");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static boolean isCollectionAreEquals(Collection expected, Collection result) {
|
||||
if(expected.size() != result.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Iterator expectedit = expected.iterator();
|
||||
while(expectedit.hasNext()) {
|
||||
final Object exp = expectedit.next();
|
||||
final Iterator responseit = result.iterator();
|
||||
boolean found = false;
|
||||
while(responseit.hasNext() && !found) {
|
||||
final Object resp = responseit.next();
|
||||
if(exp instanceof byte[] && resp instanceof byte[]) {
|
||||
final byte[] bexp = (byte[]) exp;
|
||||
final byte[] bresp = (byte[]) resp;
|
||||
if(Arrays.equals(bexp, bresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof Set && resp instanceof Set) {
|
||||
final Set subexp = (Set) exp;
|
||||
final Set subresp = (Set) resp;
|
||||
if(isSetAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof List && resp instanceof List) {
|
||||
final List subexp = (List) exp;
|
||||
final List subresp = (List) resp;
|
||||
if(isListAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof Collection && resp instanceof Collection) {
|
||||
final Collection subexp = (Collection) exp;
|
||||
final Collection subresp = (Collection) resp;
|
||||
if(isCollectionAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if (null != exp) {
|
||||
if (exp.equals(resp)){
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if(resp == null) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!found){
|
||||
fail("Result doesn't contain " + (null != exp ? exp.toString() : null));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static boolean isSetAreEquals(Set expected, Set result) {
|
||||
if(expected.size() != result.size()) {
|
||||
@@ -80,6 +137,12 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
if(isListAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else if (exp instanceof Collection && resp instanceof Collection) {
|
||||
final Collection subexp = (Collection) exp;
|
||||
final Collection subresp = (Collection) resp;
|
||||
if(isCollectionAreEquals(subexp, subresp)) {
|
||||
found = true;
|
||||
}
|
||||
} else {
|
||||
if (null != exp) {
|
||||
if (exp.equals(resp)){
|
||||
@@ -131,6 +194,12 @@ public class JedisTest extends JedisCommandTestBase {
|
||||
if(isListAreEquals(subexp, subresp)) {
|
||||
continue;
|
||||
}
|
||||
} else if (exp instanceof Collection && resp instanceof Collection) {
|
||||
final Collection subexp = (Collection) exp;
|
||||
final Collection subresp = (Collection) resp;
|
||||
if(isCollectionAreEquals(subexp, subresp)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (null != exp) {
|
||||
if (exp.equals(resp)){
|
||||
|
||||
@@ -249,11 +249,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
hash.put("car", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
|
||||
Set<String> vals = jedis.hvals("foo");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
Collection<String> vals = jedis.hvals("foo");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("car");
|
||||
expected.add("bar");
|
||||
assertTrue(JedisTest.isSetAreEquals(expected, vals));
|
||||
assertTrue(JedisTest.isCollectionAreEquals(expected, vals));
|
||||
|
||||
//Binary
|
||||
Map<byte[], byte[]> bhash = new LinkedHashMap<byte[], byte[]>();
|
||||
@@ -261,11 +261,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
bhash.put(bcar, bbar);
|
||||
jedis.hmset(bfoo, bhash);
|
||||
|
||||
Set<byte[]> bvals = jedis.hvals(bfoo);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
Collection<byte[]> bvals = jedis.hvals(bfoo);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bcar);
|
||||
bexpected.add(bbar);
|
||||
assertTrue(JedisTest.isSetAreEquals(bexpected, bvals));
|
||||
assertTrue(JedisTest.isCollectionAreEquals(bexpected, bvals));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user