Apply binary PF* commands to BinaryJedis, BinaryShardedJedis

* Apply binary PF* commands to BinaryJedis, BinaryShardedJedis
* binary PF* commands to interface
** pfadd / pfcount : BinaryJedisCommands
** pfmerge : MultiKeyBinaryCommands
This commit is contained in:
Jungtaek Lim
2014-04-05 23:21:47 +09:00
parent 1345b5c1da
commit 11f05ec161
5 changed files with 100 additions and 0 deletions

View File

@@ -3417,4 +3417,25 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
return client.getIntegerReply();
}
@Override
public Long pfadd(final byte[] key, final byte[]... elements) {
checkIsInMulti();
client.pfadd(key, elements);
return client.getIntegerReply();
}
@Override
public long pfcount(final byte[] key) {
checkIsInMulti();
client.pfcount(key);
return client.getIntegerReply();
}
@Override
public String pfmerge(final byte[] destkey, final byte[]... sourcekeys) {
checkIsInMulti();
client.pfmerge(destkey, sourcekeys);
return client.getStatusCodeReply();
}
}

View File

@@ -211,4 +211,8 @@ public interface BinaryJedisCommands {
Long bitcount(final byte[] key);
Long bitcount(final byte[] key, long start, long end);
Long pfadd(final byte[] key, final byte[]... elements);
long pfcount(final byte[] key);
}

View File

@@ -569,4 +569,17 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
Jedis j = getShard(key);
return j.bitcount(key, start, end);
}
@Override
public Long pfadd(final byte[] key, final byte[]... elements) {
Jedis j = getShard(key);
return j.pfadd(key, elements);
}
@Override
public long pfcount(final byte[] key) {
Jedis j = getShard(key);
return j.pfcount(key);
}
}

View File

@@ -69,4 +69,6 @@ public interface MultiKeyBinaryCommands {
byte[] randomBinaryKey();
Long bitop(BitOP op, final byte[] destKey, byte[]... srcKeys);
String pfmerge(final byte[] destkey, final byte[]... sourcekeys);
}

View File

@@ -2,6 +2,8 @@ package redis.clients.jedis.tests.commands;
import org.junit.Test;
import redis.clients.util.SafeEncoder;
public class HyperLogLogCommandsTest extends JedisCommandTestBase {
@@ -14,6 +16,19 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
assertEquals(0, status);
}
@Test
public void pfaddBinary() {
byte[] bFoo = SafeEncoder.encode("foo");
byte[] bBar = SafeEncoder.encode("bar");
byte[] bBar2 = SafeEncoder.encode("bar2");
long status = jedis.pfadd(bFoo, bBar, bBar2);
assertEquals(1, status);
status = jedis.pfadd(bFoo, bBar, bBar2);
assertEquals(0, status);
}
@Test
public void pfcount() {
long status = jedis.pfadd("hll", "foo", "bar", "zap");
@@ -29,6 +44,26 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
assertEquals(3, status);
}
@Test
public void pfcountBinary() {
byte[] bHll = SafeEncoder.encode("hll");
byte[] bFoo = SafeEncoder.encode("foo");
byte[] bBar = SafeEncoder.encode("bar");
byte[] bZap = SafeEncoder.encode("zap");
long status = jedis.pfadd(bHll, bFoo, bBar, bZap);
assertEquals(1, status);
status = jedis.pfadd(bHll, bZap, bZap, bZap);
assertEquals(0, status);
status = jedis.pfadd(bHll, bFoo, bBar);
assertEquals(0, status);
status = jedis.pfcount(bHll);
assertEquals(3, status);
}
@Test
public void pfmerge() {
long status = jedis.pfadd("hll1", "foo", "bar", "zap", "a");
@@ -43,4 +78,29 @@ public class HyperLogLogCommandsTest extends JedisCommandTestBase {
status = jedis.pfcount("hll3");
assertEquals(6, status);
}
@Test
public void pfmergeBinary() {
byte[] bHll1 = SafeEncoder.encode("hll1");
byte[] bHll2 = SafeEncoder.encode("hll2");
byte[] bHll3 = SafeEncoder.encode("hll3");
byte[] bFoo = SafeEncoder.encode("foo");
byte[] bBar = SafeEncoder.encode("bar");
byte[] bZap = SafeEncoder.encode("zap");
byte[] bA = SafeEncoder.encode("a");
byte[] bB = SafeEncoder.encode("b");
byte[] bC = SafeEncoder.encode("c");
long status = jedis.pfadd(bHll1, bFoo, bBar, bZap, bA);
assertEquals(1, status);
status = jedis.pfadd(bHll2, bA, bB, bC, bFoo);
assertEquals(1, status);
String mergeStatus = jedis.pfmerge(bHll3, bHll1, bHll2);
assertEquals("OK", mergeStatus);
status = jedis.pfcount("hll3");
assertEquals(6, status);
}
}