exists, sismember and hexists return Boolean instead of long

This commit is contained in:
Jonathan Leibiusky
2010-11-30 12:51:01 -03:00
parent 81ec9f8af3
commit cd9e17a709
11 changed files with 70 additions and 86 deletions

View File

@@ -91,12 +91,12 @@ public class BinaryJedis implements BinaryJedisCommands {
* Time complexity: O(1)
*
* @param key
* @return Integer reply, "0" if the key exists, otherwise "1"
* @return Integer reply, "1" if the key exists, otherwise "0"
*/
public Long exists(final byte[] key) {
public Boolean exists(final byte[] key) {
checkIsInMulti();
client.exists(key);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**
@@ -784,10 +784,10 @@ public class BinaryJedis implements BinaryJedisCommands {
* @return Return 1 if the hash stored at key contains the specified field.
* Return 0 if the key is not found or the field is not present.
*/
public Long hexists(final byte[] key, final byte[] field) {
public Boolean hexists(final byte[] key, final byte[] field) {
checkIsInMulti();
client.hexists(key, field);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**
@@ -1280,10 +1280,10 @@ public class BinaryJedis implements BinaryJedisCommands {
* set 0 if the element is not a member of the set OR if the key
* does not exist
*/
public Long sismember(final byte[] key, final byte[] member) {
public Boolean sismember(final byte[] key, final byte[] member) {
checkIsInMulti();
client.sismember(key, member);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**

View File

@@ -15,7 +15,7 @@ public interface BinaryJedisCommands {
byte[] get(byte[] key);
Long exists(byte[] key);
Boolean exists(byte[] key);
String type(byte[] key);
@@ -55,7 +55,7 @@ public interface BinaryJedisCommands {
Long hincrBy(byte[] key, byte[] field, int value);
Long hexists(byte[] key, byte[] field);
Boolean hexists(byte[] key, byte[] field);
Long hdel(byte[] key, byte[] field);
@@ -97,7 +97,7 @@ public interface BinaryJedisCommands {
Long scard(byte[] key);
Long sismember(byte[] key, byte[] member);
Boolean sismember(byte[] key, byte[] member);
byte[] srandmember(byte[] key);
@@ -131,29 +131,17 @@ public interface BinaryJedisCommands {
Set<byte[]> zrangeByScore(byte[] key, double min, double max);
Set<byte[]> zrangeByScore(
byte[] key,
double min,
double max,
int offset,
int count);
Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset,
int count);
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
Set<Tuple> zrangeByScoreWithScores(
byte[] key,
double min,
double max,
int offset,
int count);
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
int offset, int count);
Long zremrangeByRank(byte[] key, int start, int end);
Long zremrangeByScore(byte[] key, double start, double end);
Long linsert(
byte[] key,
LIST_POSITION where,
byte[] pivot,
byte[] value);
Long linsert(byte[] key, LIST_POSITION where, byte[] pivot, byte[] value);
}

View File

@@ -50,7 +50,7 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.get(key);
}
public Long exists(byte[] key) {
public Boolean exists(byte[] key) {
Jedis j = getShard(key);
return j.exists(key);
}
@@ -150,7 +150,7 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.hincrBy(key, field, value);
}
public Long hexists(byte[] key, byte[] field) {
public Boolean hexists(byte[] key, byte[] field) {
Jedis j = getShard(key);
return j.hexists(key, field);
}
@@ -255,7 +255,7 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
return j.scard(key);
}
public Long sismember(byte[] key, byte[] member) {
public Boolean sismember(byte[] key, byte[] member) {
Jedis j = getShard(key);
return j.sismember(key, member);
}

View File

@@ -78,19 +78,19 @@ public class Jedis extends BinaryJedis implements JedisCommands {
}
/**
* Test if the specified key exists. The command returns "0" if the key
* Test if the specified key exists. The command returns "1" if the key
* exists, otherwise "1" is returned. Note that even keys set with an empty
* string as value will return "1".
* string as value will return "0".
*
* Time complexity: O(1)
*
* @param key
* @return Integer reply, "0" if the key exists, otherwise "1"
*/
public Long exists(final String key) {
public Boolean exists(final String key) {
runChecks();
client.exists(key);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**
@@ -782,10 +782,10 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* @return Return 1 if the hash stored at key contains the specified field.
* Return 0 if the key is not found or the field is not present.
*/
public Long hexists(final String key, final String field) {
public Boolean hexists(final String key, final String field) {
runChecks();
client.hexists(key, field);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**
@@ -1278,10 +1278,10 @@ public class Jedis extends BinaryJedis implements JedisCommands {
* set 0 if the element is not a member of the set OR if the key
* does not exist
*/
public Long sismember(final String key, final String member) {
public Boolean sismember(final String key, final String member) {
runChecks();
client.sismember(key, member);
return client.getIntegerReply();
return client.getIntegerReply() == 1;
}
/**

View File

@@ -13,7 +13,7 @@ public interface JedisCommands {
String get(String key);
Long exists(String key);
Boolean exists(String key);
String type(String key);
@@ -53,7 +53,7 @@ public interface JedisCommands {
Long hincrBy(String key, String field, int value);
Long hexists(String key, String field);
Boolean hexists(String key, String field);
Long hdel(String key, String field);
@@ -95,7 +95,7 @@ public interface JedisCommands {
Long scard(String key);
Long sismember(String key, String member);
Boolean sismember(String key, String member);
String srandmember(String key);
@@ -129,18 +129,18 @@ public interface JedisCommands {
Set<String> zrangeByScore(String key, double min, double max);
Set<String> zrangeByScore(String key, double min, double max,
int offset, int count);
Set<String> zrangeByScore(String key, double min, double max, int offset,
int count);
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max);
Set<Tuple> zrangeByScoreWithScores(String key, double min,
double max, int offset, int count);
Set<Tuple> zrangeByScoreWithScores(String key, double min, double max,
int offset, int count);
Long zremrangeByRank(String key, int start, int end);
Long zremrangeByScore(String key, double start, double end);
Long linsert(String key, Client.LIST_POSITION where, String pivot,
String value);
String value);
}

View File

@@ -29,7 +29,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
}
@Override
public void disconnect() throws IOException {
public void disconnect() throws IOException {
for (Jedis jedis : getAllShards()) {
jedis.quit();
jedis.disconnect();
@@ -46,7 +46,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.get(key);
}
public Long exists(String key) {
public Boolean exists(String key) {
Jedis j = getShard(key);
return j.exists(key);
}
@@ -146,7 +146,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.hincrBy(key, field, value);
}
public Long hexists(String key, String field) {
public Boolean hexists(String key, String field) {
Jedis j = getShard(key);
return j.hexists(key, field);
}
@@ -251,7 +251,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
return j.scard(key);
}
public Long sismember(String key, String member) {
public Boolean sismember(String key, String member) {
Jedis j = getShard(key);
return j.sismember(key, member);
}

View File

@@ -52,6 +52,5 @@ public class JedisTest extends JedisCommandTestBase {
// every 10 seconds or so
Thread.sleep(20000);
jedis.hmget("foobar", "foo");
jedis.configSet("timeout", "300");
}
}

View File

@@ -37,23 +37,23 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
status = jedis.set(bfoo, bbar);
assertEquals("OK", status);
long reply = jedis.exists("foo");
assertEquals(1, reply);
boolean reply = jedis.exists("foo");
assertTrue(reply);
reply = jedis.exists(bfoo);
assertEquals(1, reply);
assertTrue(reply);
reply = jedis.del("foo");
assertEquals(1, reply);
long lreply = jedis.del("foo");
assertEquals(1, lreply);
reply = jedis.del(bfoo);
assertEquals(1, reply);
lreply = jedis.del(bfoo);
assertEquals(1, lreply);
reply = jedis.exists("foo");
assertEquals(0, reply);
assertFalse(reply);
reply = jedis.exists(bfoo);
assertEquals(0, reply);
assertFalse(reply);
}
@Test
@@ -65,12 +65,12 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
long reply = jedis.del("foo1", "foo2", "foo3");
assertEquals(3, reply);
reply = jedis.exists("foo1");
assertEquals(0, reply);
reply = jedis.exists("foo2");
assertEquals(0, reply);
reply = jedis.exists("foo3");
assertEquals(0, reply);
Boolean breply = jedis.exists("foo1");
assertFalse(breply);
breply = jedis.exists("foo2");
assertFalse(breply);
breply = jedis.exists("foo3");
assertFalse(breply);
jedis.set("foo1", "bar1");
@@ -88,12 +88,12 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
reply = jedis.del(bfoo1, bfoo2, bfoo3);
assertEquals(3, reply);
reply = jedis.exists(bfoo1);
assertEquals(0, reply);
reply = jedis.exists(bfoo2);
assertEquals(0, reply);
reply = jedis.exists(bfoo3);
assertEquals(0, reply);
breply = jedis.exists(bfoo1);
assertFalse(breply);
breply = jedis.exists(bfoo2);
assertFalse(breply);
breply = jedis.exists(bfoo3);
assertFalse(breply);
jedis.set(bfoo1, bbar1);

View File

@@ -150,9 +150,9 @@ public class HashesCommandsTest extends JedisCommandTestBase {
hash.put("car", "bar");
jedis.hmset("foo", hash);
assertEquals(0, jedis.hexists("bar", "foo").intValue());
assertEquals(0, jedis.hexists("foo", "foo").intValue());
assertEquals(1, jedis.hexists("foo", "bar").intValue());
assertFalse(jedis.hexists("bar", "foo"));
assertFalse(jedis.hexists("foo", "foo"));
assertTrue(jedis.hexists("foo", "bar"));
// Binary
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
@@ -160,9 +160,9 @@ public class HashesCommandsTest extends JedisCommandTestBase {
bhash.put(bcar, bbar);
jedis.hmset(bfoo, bhash);
assertEquals(0, jedis.hexists(bbar, bfoo).intValue());
assertEquals(0, jedis.hexists(bfoo, bfoo).intValue());
assertEquals(1, jedis.hexists(bfoo, bbar).intValue());
assertFalse(jedis.hexists(bbar, bfoo));
assertFalse(jedis.hexists(bfoo, bfoo));
assertTrue(jedis.hexists(bfoo, bbar));
}

View File

@@ -28,6 +28,7 @@ public abstract class JedisCommandTestBase extends JedisTestBase {
jedis = new Jedis(hnp.host, hnp.port, 500);
jedis.connect();
jedis.auth("foobared");
jedis.configSet("timeout", "300");
jedis.flushAll();
}

View File

@@ -199,21 +199,17 @@ public class SetCommandsTest extends JedisCommandTestBase {
jedis.sadd("foo", "a");
jedis.sadd("foo", "b");
long status = jedis.sismember("foo", "a");
assertEquals(1, status);
assertTrue(jedis.sismember("foo", "a"));
status = jedis.sismember("foo", "c");
assertEquals(0, status);
assertFalse(jedis.sismember("foo", "c"));
// Binary
jedis.sadd(bfoo, ba);
jedis.sadd(bfoo, bb);
long bstatus = jedis.sismember(bfoo, ba);
assertEquals(1, bstatus);
assertTrue(jedis.sismember(bfoo, ba));
bstatus = jedis.sismember(bfoo, bc);
assertEquals(0, bstatus);
assertFalse(jedis.sismember(bfoo, bc));
}