Hashes hkeys and hvals refactored to return a set instead of a list.
It looks like the order is not guaranted, so a set seems much adapted than a list.
This commit is contained in:
@@ -829,10 +829,11 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* @param key
|
||||
* @return All the fields names contained into a hash.
|
||||
*/
|
||||
public List<byte[]> hkeys(final byte[] key) {
|
||||
public Set<byte[]> hkeys(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.hkeys(key);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
final List<byte[]> lresult = client.getBinaryMultiBulkReply();
|
||||
return new HashSet<byte[]>(lresult);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -843,10 +844,11 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
* @param key
|
||||
* @return All the fields values contained into a hash.
|
||||
*/
|
||||
public List<byte[]> hvals(final byte[] key) {
|
||||
public Set<byte[]> hvals(final byte[] key) {
|
||||
checkIsInMulti();
|
||||
client.hvals(key);
|
||||
return client.getBinaryMultiBulkReply();
|
||||
final List<byte[]> lresult = client.getBinaryMultiBulkReply();
|
||||
return new HashSet<byte[]>(lresult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,9 +60,9 @@ public interface BinaryJedisCommands {
|
||||
|
||||
Integer hlen(byte[] key);
|
||||
|
||||
List<byte[]> hkeys(byte[] key);
|
||||
Set<byte[]> hkeys(byte[] key);
|
||||
|
||||
List<byte[]> hvals(byte[] key);
|
||||
Set<byte[]> hvals(byte[] key);
|
||||
|
||||
Map<byte[], byte[]> hgetAll(byte[] key);
|
||||
|
||||
|
||||
@@ -164,12 +164,12 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo> implement
|
||||
return j.hlen(key);
|
||||
}
|
||||
|
||||
public List<byte[]> hkeys(byte[] key) {
|
||||
public Set<byte[]> hkeys(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public List<byte[]> hvals(byte[] key) {
|
||||
public Set<byte[]> hvals(byte[] key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
|
||||
@@ -758,10 +758,11 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* @param key
|
||||
* @return All the fields names contained into a hash.
|
||||
*/
|
||||
public List<String> hkeys(final String key) {
|
||||
public Set<String> hkeys(final String key) {
|
||||
checkIsInMulti();
|
||||
client.hkeys(key);
|
||||
return client.getMultiBulkReply();
|
||||
final List<String> lresult = client.getMultiBulkReply();
|
||||
return new HashSet<String>(lresult);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -772,10 +773,11 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
* @param key
|
||||
* @return All the fields values contained into a hash.
|
||||
*/
|
||||
public List<String> hvals(final String key) {
|
||||
public Set<String> hvals(final String key) {
|
||||
checkIsInMulti();
|
||||
client.hvals(key);
|
||||
return client.getMultiBulkReply();
|
||||
final List<String> lresult = client.getMultiBulkReply();
|
||||
return new HashSet<String>(lresult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,9 +58,9 @@ public interface JedisCommands {
|
||||
|
||||
Integer hlen(String key);
|
||||
|
||||
List<String> hkeys(String key);
|
||||
Set<String> hkeys(String key);
|
||||
|
||||
List<String> hvals(String key);
|
||||
Set<String> hvals(String key);
|
||||
|
||||
Map<String, String> hgetAll(String key);
|
||||
|
||||
|
||||
@@ -150,12 +150,12 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
return j.hlen(key);
|
||||
}
|
||||
|
||||
public List<String> hkeys(String key) {
|
||||
public Set<String> hkeys(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hkeys(key);
|
||||
}
|
||||
|
||||
public List<String> hvals(String key) {
|
||||
public Set<String> hvals(String key) {
|
||||
Jedis j = getShard(key);
|
||||
return j.hvals(key);
|
||||
}
|
||||
|
||||
@@ -222,11 +222,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
hash.put("car", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
|
||||
List<String> keys = jedis.hkeys("foo");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
Set<String> keys = jedis.hkeys("foo");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("bar");
|
||||
expected.add("car");
|
||||
assertTrue(JedisTest.isListAreEquals(expected, keys));
|
||||
assertTrue(JedisTest.isSetAreEquals(expected, keys));
|
||||
|
||||
//Binary
|
||||
Map<byte[], byte[]> bhash = new LinkedHashMap<byte[], byte[]>();
|
||||
@@ -234,11 +234,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
bhash.put(bcar, bbar);
|
||||
jedis.hmset(bfoo, bhash);
|
||||
|
||||
List<byte[]> bkeys = jedis.hkeys(bfoo);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
Set<byte[]> bkeys = jedis.hkeys(bfoo);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bbar);
|
||||
bexpected.add(bcar);
|
||||
assertTrue(JedisTest.isListAreEquals(bexpected, bkeys));
|
||||
assertTrue(JedisTest.isSetAreEquals(bexpected, bkeys));
|
||||
|
||||
}
|
||||
|
||||
@@ -249,11 +249,11 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
hash.put("car", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
|
||||
List<String> vals = jedis.hvals("foo");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
Set<String> vals = jedis.hvals("foo");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("car");
|
||||
expected.add("bar");
|
||||
assertTrue(JedisTest.isListAreEquals(expected, vals));
|
||||
assertTrue(JedisTest.isSetAreEquals(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);
|
||||
|
||||
List<byte[]> bvals = jedis.hvals(bfoo);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
Set<byte[]> bvals = jedis.hvals(bfoo);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bcar);
|
||||
bexpected.add(bbar);
|
||||
assertTrue(JedisTest.isListAreEquals(bexpected, bvals));
|
||||
assertTrue(JedisTest.isSetAreEquals(bexpected, bvals));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user