Expose *SCAN commands to BinaryJedis
* method signatures are a bit similar to Jedis's *SCAN ** but it takes parameters to byte[] instead of String * ScanParams : allow match pattern with byte[] * ScanResult : add method to get cursor with byte[] type * *SCAN for BinaryJedis unit tests included
This commit is contained in:
@@ -11,6 +11,7 @@ import redis.clients.jedis.ScanResult;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -515,8 +516,14 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void scanMatch() {
|
||||
ScanParams params = new ScanParams();
|
||||
@@ -529,6 +536,19 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bfoostar);
|
||||
|
||||
jedis.set(bfoo1, bbar);
|
||||
jedis.set(bfoo2, bbar);
|
||||
jedis.set(bfoo3, bbar);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -543,5 +563,17 @@ public class AllKindOfValuesCommandsTest extends JedisCommandTestBase {
|
||||
ScanResult<String> result = jedis.scan(SCAN_POINTER_START, params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
jedis.set(bfoo1, bbar);
|
||||
jedis.set(bfoo2, bbar);
|
||||
jedis.set(bfoo3, bbar);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.scan(SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,18 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||
|
||||
|
||||
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||
final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' };
|
||||
|
||||
@Test
|
||||
public void hset() {
|
||||
long status = jedis.hset("foo", "bar", "car");
|
||||
@@ -300,6 +306,14 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -315,6 +329,20 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bbarstar);
|
||||
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
jedis.hset(bfoo, bbar1, bcar);
|
||||
jedis.hset(bfoo, bbar2, bcar);
|
||||
jedis.hset(bfoo, bbar3, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -330,5 +358,18 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
SCAN_POINTER_START, params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
jedis.hset(bfoo, bbar, bcar);
|
||||
jedis.hset(bfoo, bbar1, bcar);
|
||||
jedis.hset(bfoo, bbar2, bcar);
|
||||
jedis.hset(bfoo, bbar3, bcar);
|
||||
|
||||
ScanResult<Map.Entry<byte[], byte[]>> bResult = jedis.hscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.ScanParams;
|
||||
import redis.clients.jedis.ScanResult;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class SetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -19,6 +20,11 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bc = { 0x0C };
|
||||
final byte[] bd = { 0x0D };
|
||||
final byte[] bx = { 0x42 };
|
||||
|
||||
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||
final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' };
|
||||
|
||||
@Test
|
||||
public void sadd() {
|
||||
@@ -462,6 +468,14 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
jedis.sadd(bfoo, ba, bb);
|
||||
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -474,6 +488,16 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bbarstar);
|
||||
|
||||
jedis.sadd(bfoo, bbar1, bbar2, bbar3);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -486,5 +510,14 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
ScanResult<String> result = jedis.sscan("foo", SCAN_POINTER_START, params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
jedis.sadd(bfoo, bbar1, bbar2, bbar3);
|
||||
ScanResult<byte[]> bResult = jedis.sscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import redis.clients.jedis.Tuple;
|
||||
import redis.clients.jedis.ZParams;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
|
||||
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START_BINARY;
|
||||
|
||||
public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -19,6 +20,11 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] ba = { 0x0A };
|
||||
final byte[] bb = { 0x0B };
|
||||
final byte[] bc = { 0x0C };
|
||||
|
||||
final byte[] bbar1 = { 0x05, 0x06, 0x07, 0x08, 0x0A };
|
||||
final byte[] bbar2 = { 0x05, 0x06, 0x07, 0x08, 0x0B };
|
||||
final byte[] bbar3 = { 0x05, 0x06, 0x07, 0x08, 0x0C };
|
||||
final byte[] bbarstar = { 0x05, 0x06, 0x07, 0x08, '*' };
|
||||
|
||||
@Test
|
||||
public void zadd() {
|
||||
@@ -899,6 +905,15 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
jedis.zadd(bfoo, 1, ba);
|
||||
jedis.zadd(bfoo, 1, bb);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -913,6 +928,19 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertEquals(SCAN_POINTER_START, result.getStringCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.match(bbarstar);
|
||||
|
||||
jedis.zadd(bfoo, 2, bbar1);
|
||||
jedis.zadd(bfoo, 1, bbar2);
|
||||
jedis.zadd(bfoo, 11, bbar3);
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertArrayEquals(SCAN_POINTER_START_BINARY, bResult.getBinaryCursor());
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -929,5 +957,17 @@ public class SortedSetCommandsTest extends JedisCommandTestBase {
|
||||
ScanResult<Tuple> result = jedis.zscan("foo", SCAN_POINTER_START, params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
|
||||
// binary
|
||||
params = new ScanParams();
|
||||
params.count(2);
|
||||
|
||||
jedis.zadd(bfoo, 2, bbar1);
|
||||
jedis.zadd(bfoo, 1, bbar2);
|
||||
jedis.zadd(bfoo, 11, bbar3);
|
||||
|
||||
ScanResult<Tuple> bResult = jedis.zscan(bfoo, SCAN_POINTER_START_BINARY, params);
|
||||
|
||||
assertFalse(bResult.getResult().isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user