Merged with master
This commit is contained in:
@@ -8,7 +8,7 @@ import redis.clients.jedis.BuilderFactory;
|
||||
public class BuilderFactoryTest extends Assert {
|
||||
@Test
|
||||
public void buildDouble() {
|
||||
Double build = BuilderFactory.DOUBLE.build("1.0".getBytes());
|
||||
assertEquals(new Double(1.0), build);
|
||||
Double build = BuilderFactory.DOUBLE.build("1.0".getBytes());
|
||||
assertEquals(new Double(1.0), build);
|
||||
}
|
||||
}
|
||||
@@ -13,31 +13,31 @@ public class ConnectionTest extends Assert {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
client = new Connection();
|
||||
client = new Connection();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
client.disconnect();
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkUnkownHost() {
|
||||
client.setHost("someunknownhost");
|
||||
client.connect();
|
||||
client.setHost("someunknownhost");
|
||||
client.connect();
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
public void checkWrongPort() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(55665);
|
||||
client.connect();
|
||||
client.setHost("localhost");
|
||||
client.setPort(55665);
|
||||
client.connect();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void connectIfNotConnectedWhenSettingTimeoutInfinite() {
|
||||
client.setHost("localhost");
|
||||
client.setPort(6379);
|
||||
client.setPort(6379);
|
||||
client.setTimeoutInfinite();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,22 +9,22 @@ public class FragmentedByteArrayInputStream extends ByteArrayInputStream {
|
||||
private int readMethodCallCount = 0;
|
||||
|
||||
public FragmentedByteArrayInputStream(final byte[] buf) {
|
||||
super(buf);
|
||||
super(buf);
|
||||
}
|
||||
|
||||
public synchronized int read(final byte[] b, final int off, final int len) {
|
||||
readMethodCallCount++;
|
||||
if (len <= 10) {
|
||||
// if the len <= 10, return as usual ..
|
||||
return super.read(b, off, len);
|
||||
} else {
|
||||
// else return the first half ..
|
||||
return super.read(b, off, len / 2);
|
||||
}
|
||||
readMethodCallCount++;
|
||||
if (len <= 10) {
|
||||
// if the len <= 10, return as usual ..
|
||||
return super.read(b, off, len);
|
||||
} else {
|
||||
// else return the first half ..
|
||||
return super.read(b, off, len / 2);
|
||||
}
|
||||
}
|
||||
|
||||
public int getReadMethodCallCount() {
|
||||
return readMethodCallCount;
|
||||
return readMethodCallCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,59 +19,59 @@ public class JedisPoolTest extends Assert {
|
||||
|
||||
@Test
|
||||
public void checkConnections() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort(), 2000);
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkConnectionWithDefaultPort() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort());
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort());
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "bar");
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkJedisIsReusedWhenReturned() {
|
||||
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort());
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "0");
|
||||
pool.returnResource(jedis);
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort());
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.set("foo", "0");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.incr("foo");
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.incr("foo");
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPoolRepairedWhenJedisIsBroken() {
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort());
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.quit();
|
||||
pool.returnBrokenResource(jedis);
|
||||
JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
|
||||
hnp.getPort());
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.quit();
|
||||
pool.returnBrokenResource(jedis);
|
||||
|
||||
jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.incr("foo");
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
jedis = pool.getResource();
|
||||
jedis.auth("foobared");
|
||||
jedis.incr("foo");
|
||||
pool.returnResource(jedis);
|
||||
pool.destroy();
|
||||
}
|
||||
|
||||
@Test(expected = JedisConnectionException.class)
|
||||
@@ -93,8 +93,8 @@ public class JedisPoolTest extends Assert {
|
||||
public void securePool() {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setTestOnBorrow(true);
|
||||
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(), 2000,
|
||||
"foobared");
|
||||
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
|
||||
2000, "foobared");
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("foo", "bar");
|
||||
pool.returnResource(jedis);
|
||||
@@ -177,25 +177,25 @@ public class JedisPoolTest extends Assert {
|
||||
pool0.returnResource(jedis);
|
||||
pool0.destroy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void returnResourceShouldResetState() {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setBlockWhenExhausted(false);
|
||||
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
|
||||
2000, "foobared");
|
||||
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("hello", "jedis");
|
||||
Transaction t = jedis.multi();
|
||||
t.set("hello", "world");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
Jedis jedis2 = pool.getResource();
|
||||
assertTrue(jedis == jedis2);
|
||||
assertEquals("jedis", jedis2.get("hello"));
|
||||
pool.returnResource(jedis2);
|
||||
pool.destroy();
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setBlockWhenExhausted(false);
|
||||
JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
|
||||
2000, "foobared");
|
||||
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("hello", "jedis");
|
||||
Transaction t = jedis.multi();
|
||||
t.set("hello", "world");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
Jedis jedis2 = pool.getResource();
|
||||
assertTrue(jedis == jedis2);
|
||||
assertEquals("jedis", jedis2.get("hello"));
|
||||
pool.returnResource(jedis2);
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.junit.Test;
|
||||
import redis.clients.jedis.DebugParams;
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
import redis.clients.jedis.JedisSentinelPool;
|
||||
import redis.clients.jedis.Transaction;
|
||||
@@ -154,22 +153,22 @@ public class JedisSentinelPoolTest extends JedisTestBase {
|
||||
|
||||
@Test
|
||||
public void returnResourceShouldResetState() {
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setBlockWhenExhausted(false);
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
|
||||
config, 1000, "foobared", 2);
|
||||
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("hello", "jedis");
|
||||
Transaction t = jedis.multi();
|
||||
t.set("hello", "world");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
Jedis jedis2 = pool.getResource();
|
||||
assertTrue(jedis == jedis2);
|
||||
assertEquals("jedis", jedis2.get("hello"));
|
||||
pool.returnResource(jedis2);
|
||||
pool.destroy();
|
||||
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
|
||||
config.setMaxTotal(1);
|
||||
config.setBlockWhenExhausted(false);
|
||||
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
|
||||
config, 1000, "foobared", 2);
|
||||
|
||||
Jedis jedis = pool.getResource();
|
||||
jedis.set("hello", "jedis");
|
||||
Transaction t = jedis.multi();
|
||||
t.set("hello", "world");
|
||||
pool.returnResource(jedis);
|
||||
|
||||
Jedis jedis2 = pool.getResource();
|
||||
assertTrue(jedis == jedis2);
|
||||
assertEquals("jedis", jedis2.get("hello"));
|
||||
pool.returnResource(jedis2);
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,18 @@ import org.junit.Assert;
|
||||
|
||||
public abstract class JedisTestBase extends Assert {
|
||||
protected void assertEquals(List<byte[]> expected, List<byte[]> actual) {
|
||||
assertEquals(expected.size(), actual.size());
|
||||
for (int n = 0; n < expected.size(); n++) {
|
||||
assertArrayEquals(expected.get(n), actual.get(n));
|
||||
}
|
||||
assertEquals(expected.size(), actual.size());
|
||||
for (int n = 0; n < expected.size(); n++) {
|
||||
assertArrayEquals(expected.get(n), actual.get(n));
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertEquals(Set<byte[]> expected, Set<byte[]> actual) {
|
||||
assertEquals(expected.size(), actual.size());
|
||||
Iterator<byte[]> iterator = expected.iterator();
|
||||
Iterator<byte[]> iterator2 = actual.iterator();
|
||||
while (iterator.hasNext() || iterator2.hasNext()) {
|
||||
assertArrayEquals(iterator.next(), iterator2.next());
|
||||
}
|
||||
assertEquals(expected.size(), actual.size());
|
||||
Iterator<byte[]> iterator = expected.iterator();
|
||||
Iterator<byte[]> iterator2 = actual.iterator();
|
||||
while (iterator.hasNext() || iterator2.hasNext()) {
|
||||
assertArrayEquals(iterator.next(), iterator2.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,307 +27,321 @@ public class PipeliningTest extends Assert {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipeline() throws UnsupportedEncodingException {
|
||||
List<Object> results = jedis.pipelined(new PipelineBlock() {
|
||||
public void execute() {
|
||||
set("foo", "bar");
|
||||
get("foo");
|
||||
}
|
||||
});
|
||||
List<Object> results = jedis.pipelined(new PipelineBlock() {
|
||||
public void execute() {
|
||||
set("foo", "bar");
|
||||
get("foo");
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
p.get("foo");
|
||||
results = p.syncAndReturnAll();
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
p.get("foo");
|
||||
results = p.syncAndReturnAll();
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("OK", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineResponse() {
|
||||
jedis.set("string", "foo");
|
||||
jedis.lpush("list", "foo");
|
||||
jedis.hset("hash", "foo", "bar");
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
jedis.sadd("set", "foo");
|
||||
jedis.set("string", "foo");
|
||||
jedis.lpush("list", "foo");
|
||||
jedis.hset("hash", "foo", "bar");
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
jedis.sadd("set", "foo");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
Response<String> list = p.lpop("list");
|
||||
Response<String> hash = p.hget("hash", "foo");
|
||||
Response<Set<String>> zset = p.zrange("zset", 0, -1);
|
||||
Response<String> set = p.spop("set");
|
||||
Response<Boolean> blist = p.exists("list");
|
||||
Response<Double> zincrby = p.zincrby("zset", 1, "foo");
|
||||
Response<Long> zcard = p.zcard("zset");
|
||||
p.lpush("list", "bar");
|
||||
Response<List<String>> lrange = p.lrange("list", 0, -1);
|
||||
Response<Map<String, String>> hgetAll = p.hgetAll("hash");
|
||||
p.sadd("set", "foo");
|
||||
Response<Set<String>> smembers = p.smembers("set");
|
||||
Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0,
|
||||
-1);
|
||||
p.sync();
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
Response<String> list = p.lpop("list");
|
||||
Response<String> hash = p.hget("hash", "foo");
|
||||
Response<Set<String>> zset = p.zrange("zset", 0, -1);
|
||||
Response<String> set = p.spop("set");
|
||||
Response<Boolean> blist = p.exists("list");
|
||||
Response<Double> zincrby = p.zincrby("zset", 1, "foo");
|
||||
Response<Long> zcard = p.zcard("zset");
|
||||
p.lpush("list", "bar");
|
||||
Response<List<String>> lrange = p.lrange("list", 0, -1);
|
||||
Response<Map<String, String>> hgetAll = p.hgetAll("hash");
|
||||
p.sadd("set", "foo");
|
||||
Response<Set<String>> smembers = p.smembers("set");
|
||||
Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0,
|
||||
-1);
|
||||
p.sync();
|
||||
|
||||
assertEquals("foo", string.get());
|
||||
assertEquals("foo", list.get());
|
||||
assertEquals("bar", hash.get());
|
||||
assertEquals("foo", zset.get().iterator().next());
|
||||
assertEquals("foo", set.get());
|
||||
assertEquals(false, blist.get());
|
||||
assertEquals(Double.valueOf(2), zincrby.get());
|
||||
assertEquals(Long.valueOf(1), zcard.get());
|
||||
assertEquals(1, lrange.get().size());
|
||||
assertNotNull(hgetAll.get().get("foo"));
|
||||
assertEquals(1, smembers.get().size());
|
||||
assertEquals(1, zrangeWithScores.get().size());
|
||||
assertEquals("foo", string.get());
|
||||
assertEquals("foo", list.get());
|
||||
assertEquals("bar", hash.get());
|
||||
assertEquals("foo", zset.get().iterator().next());
|
||||
assertEquals("foo", set.get());
|
||||
assertEquals(false, blist.get());
|
||||
assertEquals(Double.valueOf(2), zincrby.get());
|
||||
assertEquals(Long.valueOf(1), zcard.get());
|
||||
assertEquals(1, lrange.get().size());
|
||||
assertNotNull(hgetAll.get().get("foo"));
|
||||
assertEquals(1, smembers.get().size());
|
||||
assertEquals(1, zrangeWithScores.get().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pipelineResponseWithData() {
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Double> score = p.zscore("zset", "foo");
|
||||
p.sync();
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
|
||||
assertNotNull(score.get());
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Double> score = p.zscore("zset", "foo");
|
||||
p.sync();
|
||||
|
||||
assertNotNull(score.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineBinarySafeHashCommands() {
|
||||
jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes());
|
||||
jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes());
|
||||
jedis.hset("key".getBytes(), "f1".getBytes(), "v111".getBytes());
|
||||
jedis.hset("key".getBytes(), "f22".getBytes(), "v2222".getBytes());
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Map<byte[],byte[]>> fmap = p.hgetAll("key".getBytes());
|
||||
Response<Set<byte[]>> fkeys = p.hkeys("key".getBytes());
|
||||
Response<List<byte[]>> fordered = p.hmget("key".getBytes(), "f22".getBytes(), "f1".getBytes());
|
||||
Response<List<byte[]>> fvals = p.hvals("key".getBytes());
|
||||
p.sync();
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Map<byte[], byte[]>> fmap = p.hgetAll("key".getBytes());
|
||||
Response<Set<byte[]>> fkeys = p.hkeys("key".getBytes());
|
||||
Response<List<byte[]>> fordered = p.hmget("key".getBytes(),
|
||||
"f22".getBytes(), "f1".getBytes());
|
||||
Response<List<byte[]>> fvals = p.hvals("key".getBytes());
|
||||
p.sync();
|
||||
|
||||
assertNotNull(fmap.get());
|
||||
// we have to do these strange contortions because byte[] is not a very good key
|
||||
// for a java Map. It only works with equality (you need the exact key object to retrieve
|
||||
// the value) I recommend we switch to using ByteBuffer or something similar:
|
||||
// http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java
|
||||
Map<byte[],byte[]> map = fmap.get();
|
||||
Set<byte[]> mapKeys = map.keySet();
|
||||
Iterator<byte[]> iterMap = mapKeys.iterator();
|
||||
byte[] firstMapKey = iterMap.next();
|
||||
byte[] secondMapKey = iterMap.next();
|
||||
assertFalse(iterMap.hasNext());
|
||||
verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(), "f22".getBytes());
|
||||
byte[] firstMapValue = map.get(firstMapKey);
|
||||
byte[] secondMapValue = map.get(secondMapKey);
|
||||
verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(), "v2222".getBytes());
|
||||
assertNotNull(fmap.get());
|
||||
// we have to do these strange contortions because byte[] is not a very
|
||||
// good key
|
||||
// for a java Map. It only works with equality (you need the exact key
|
||||
// object to retrieve
|
||||
// the value) I recommend we switch to using ByteBuffer or something
|
||||
// similar:
|
||||
// http://stackoverflow.com/questions/1058149/using-a-byte-array-as-hashmap-key-java
|
||||
Map<byte[], byte[]> map = fmap.get();
|
||||
Set<byte[]> mapKeys = map.keySet();
|
||||
Iterator<byte[]> iterMap = mapKeys.iterator();
|
||||
byte[] firstMapKey = iterMap.next();
|
||||
byte[] secondMapKey = iterMap.next();
|
||||
assertFalse(iterMap.hasNext());
|
||||
verifyHasBothValues(firstMapKey, secondMapKey, "f1".getBytes(),
|
||||
"f22".getBytes());
|
||||
byte[] firstMapValue = map.get(firstMapKey);
|
||||
byte[] secondMapValue = map.get(secondMapKey);
|
||||
verifyHasBothValues(firstMapValue, secondMapValue, "v111".getBytes(),
|
||||
"v2222".getBytes());
|
||||
|
||||
assertNotNull(fkeys.get());
|
||||
Iterator<byte[]> iter = fkeys.get().iterator();
|
||||
byte[] firstKey = iter.next();
|
||||
byte[] secondKey = iter.next();
|
||||
assertFalse(iter.hasNext());
|
||||
verifyHasBothValues(firstKey, secondKey, "f1".getBytes(), "f22".getBytes());
|
||||
assertNotNull(fkeys.get());
|
||||
Iterator<byte[]> iter = fkeys.get().iterator();
|
||||
byte[] firstKey = iter.next();
|
||||
byte[] secondKey = iter.next();
|
||||
assertFalse(iter.hasNext());
|
||||
verifyHasBothValues(firstKey, secondKey, "f1".getBytes(),
|
||||
"f22".getBytes());
|
||||
|
||||
assertNotNull(fordered.get());
|
||||
assertArrayEquals("v2222".getBytes(), fordered.get().get(0));
|
||||
assertArrayEquals("v111".getBytes(), fordered.get().get(1));
|
||||
assertNotNull(fordered.get());
|
||||
assertArrayEquals("v2222".getBytes(), fordered.get().get(0));
|
||||
assertArrayEquals("v111".getBytes(), fordered.get().get(1));
|
||||
|
||||
assertNotNull(fvals.get());
|
||||
assertEquals(2, fvals.get().size());
|
||||
byte[] firstValue = fvals.get().get(0);
|
||||
byte[] secondValue = fvals.get().get(1);
|
||||
verifyHasBothValues(firstValue, secondValue, "v111".getBytes(), "v2222".getBytes());
|
||||
assertNotNull(fvals.get());
|
||||
assertEquals(2, fvals.get().size());
|
||||
byte[] firstValue = fvals.get().get(0);
|
||||
byte[] secondValue = fvals.get().get(1);
|
||||
verifyHasBothValues(firstValue, secondValue, "v111".getBytes(),
|
||||
"v2222".getBytes());
|
||||
}
|
||||
|
||||
private void verifyHasBothValues(byte[] firstKey, byte[] secondKey, byte[] value1, byte[] value2) {
|
||||
assertFalse(Arrays.equals(firstKey, secondKey));
|
||||
assertTrue(Arrays.equals(firstKey, value1) || Arrays.equals(firstKey, value2));
|
||||
assertTrue(Arrays.equals(secondKey, value1) || Arrays.equals(secondKey, value2));
|
||||
private void verifyHasBothValues(byte[] firstKey, byte[] secondKey,
|
||||
byte[] value1, byte[] value2) {
|
||||
assertFalse(Arrays.equals(firstKey, secondKey));
|
||||
assertTrue(Arrays.equals(firstKey, value1)
|
||||
|| Arrays.equals(firstKey, value2));
|
||||
assertTrue(Arrays.equals(secondKey, value1)
|
||||
|| Arrays.equals(secondKey, value2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineSelect() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.select(1);
|
||||
p.sync();
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.select(1);
|
||||
p.sync();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void pipelineResponseWithoutData() {
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Double> score = p.zscore("zset", "bar");
|
||||
p.sync();
|
||||
jedis.zadd("zset", 1, "foo");
|
||||
|
||||
assertNull(score.get());
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<Double> score = p.zscore("zset", "bar");
|
||||
p.sync();
|
||||
|
||||
assertNull(score.get());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void pipelineResponseWithinPipeline() {
|
||||
jedis.set("string", "foo");
|
||||
jedis.set("string", "foo");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
string.get();
|
||||
p.sync();
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> string = p.get("string");
|
||||
string.get();
|
||||
p.sync();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pipelineWithPubSub() {
|
||||
Pipeline pipelined = jedis.pipelined();
|
||||
Response<Long> p1 = pipelined.publish("foo", "bar");
|
||||
Response<Long> p2 = pipelined.publish("foo".getBytes(), "bar"
|
||||
.getBytes());
|
||||
pipelined.sync();
|
||||
assertEquals(0, p1.get().longValue());
|
||||
assertEquals(0, p2.get().longValue());
|
||||
Pipeline pipelined = jedis.pipelined();
|
||||
Response<Long> p1 = pipelined.publish("foo", "bar");
|
||||
Response<Long> p2 = pipelined.publish("foo".getBytes(),
|
||||
"bar".getBytes());
|
||||
pipelined.sync();
|
||||
assertEquals(0, p1.get().longValue());
|
||||
assertEquals(0, p2.get().longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canRetrieveUnsetKey() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
|
||||
p.sync();
|
||||
assertNull(shouldNotExist.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void piplineWithError(){
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
Response<Set<String>> error = p.smembers("foo");
|
||||
Response<String> r = p.get("foo");
|
||||
p.sync();
|
||||
try{
|
||||
error.get();
|
||||
fail();
|
||||
}catch(JedisDataException e){
|
||||
//that is fine we should be here
|
||||
}
|
||||
assertEquals(r.get(), "bar");
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> shouldNotExist = p.get(UUID.randomUUID().toString());
|
||||
p.sync();
|
||||
assertNull(shouldNotExist.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi(){
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.multi();
|
||||
Response<Long> r1 = p.hincrBy("a", "f1", -1);
|
||||
Response<Long> r2 = p.hincrBy("a", "f1", -2);
|
||||
Response<List<Object>> r3 = p.exec();
|
||||
List<Object> result = p.syncAndReturnAll();
|
||||
|
||||
assertEquals(new Long(-1), r1.get());
|
||||
assertEquals(new Long(-3), r2.get());
|
||||
|
||||
assertEquals(4, result.size());
|
||||
|
||||
assertEquals("OK", result.get(0));
|
||||
assertEquals("QUEUED", result.get(1));
|
||||
assertEquals("QUEUED", result.get(2));
|
||||
|
||||
//4th result is a list with the results from the multi
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> multiResult = (List<Object>) result.get(3);
|
||||
assertEquals(new Long(-1), multiResult.get(0));
|
||||
assertEquals(new Long(-3), multiResult.get(1));
|
||||
|
||||
assertEquals(new Long(-1), r3.get().get(0));
|
||||
assertEquals(new Long(-3), r3.get().get(1));
|
||||
public void piplineWithError() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set("foo", "bar");
|
||||
Response<Set<String>> error = p.smembers("foo");
|
||||
Response<String> r = p.get("foo");
|
||||
p.sync();
|
||||
try {
|
||||
error.get();
|
||||
fail();
|
||||
} catch (JedisDataException e) {
|
||||
// that is fine we should be here
|
||||
}
|
||||
assertEquals(r.get(), "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multi() {
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.multi();
|
||||
Response<Long> r1 = p.hincrBy("a", "f1", -1);
|
||||
Response<Long> r2 = p.hincrBy("a", "f1", -2);
|
||||
Response<List<Object>> r3 = p.exec();
|
||||
List<Object> result = p.syncAndReturnAll();
|
||||
|
||||
assertEquals(new Long(-1), r1.get());
|
||||
assertEquals(new Long(-3), r2.get());
|
||||
|
||||
assertEquals(4, result.size());
|
||||
|
||||
assertEquals("OK", result.get(0));
|
||||
assertEquals("QUEUED", result.get(1));
|
||||
assertEquals("QUEUED", result.get(2));
|
||||
|
||||
// 4th result is a list with the results from the multi
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> multiResult = (List<Object>) result.get(3);
|
||||
assertEquals(new Long(-1), multiResult.get(0));
|
||||
assertEquals(new Long(-3), multiResult.get(1));
|
||||
|
||||
assertEquals(new Long(-1), r3.get().get(0));
|
||||
assertEquals(new Long(-3), r3.get().get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscardInPipeline() {
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.multi();
|
||||
pipeline.set("foo", "bar");
|
||||
Response<String> discard = pipeline.discard();
|
||||
Response<String> get = pipeline.get("foo");
|
||||
pipeline.sync();
|
||||
discard.get();
|
||||
get.get();
|
||||
Pipeline pipeline = jedis.pipelined();
|
||||
pipeline.multi();
|
||||
pipeline.set("foo", "bar");
|
||||
Response<String> discard = pipeline.discard();
|
||||
Response<String> get = pipeline.get("foo");
|
||||
pipeline.sync();
|
||||
discard.get();
|
||||
get.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEval() {
|
||||
String script = "return 'success!'";
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> result = p.eval(script);
|
||||
p.sync();
|
||||
@Test
|
||||
public void testEval() {
|
||||
String script = "return 'success!'";
|
||||
|
||||
assertEquals("success!", result.get());
|
||||
}
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> result = p.eval(script);
|
||||
p.sync();
|
||||
|
||||
@Test
|
||||
public void testEvalKeyAndArg() {
|
||||
String key = "test";
|
||||
String arg = "3";
|
||||
String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
|
||||
assertEquals("success!", result.get());
|
||||
}
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set(key, "0");
|
||||
Response<String> result0 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
|
||||
p.incr(key);
|
||||
Response<String> result1 = p.eval(script, Arrays.asList(key), Arrays.asList(arg));
|
||||
Response<String> result2 = p.get(key);
|
||||
p.sync();
|
||||
@Test
|
||||
public void testEvalKeyAndArg() {
|
||||
String key = "test";
|
||||
String arg = "3";
|
||||
String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
|
||||
|
||||
assertNull(result0.get());
|
||||
assertNull(result1.get());
|
||||
assertEquals("13", result2.get());
|
||||
}
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set(key, "0");
|
||||
Response<String> result0 = p.eval(script, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
p.incr(key);
|
||||
Response<String> result1 = p.eval(script, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
Response<String> result2 = p.get(key);
|
||||
p.sync();
|
||||
|
||||
@Test
|
||||
public void testEvalsha() {
|
||||
String script = "return 'success!'";
|
||||
String sha1 = jedis.scriptLoad(script);
|
||||
assertNull(result0.get());
|
||||
assertNull(result1.get());
|
||||
assertEquals("13", result2.get());
|
||||
}
|
||||
|
||||
assertTrue(jedis.scriptExists(sha1));
|
||||
@Test
|
||||
public void testEvalsha() {
|
||||
String script = "return 'success!'";
|
||||
String sha1 = jedis.scriptLoad(script);
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> result = p.evalsha(sha1);
|
||||
p.sync();
|
||||
assertTrue(jedis.scriptExists(sha1));
|
||||
|
||||
assertEquals("success!", result.get());
|
||||
}
|
||||
Pipeline p = jedis.pipelined();
|
||||
Response<String> result = p.evalsha(sha1);
|
||||
p.sync();
|
||||
|
||||
@Test
|
||||
public void testEvalshaKeyAndArg() {
|
||||
String key = "test";
|
||||
String arg = "3";
|
||||
String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
|
||||
String sha1 = jedis.scriptLoad(script);
|
||||
assertEquals("success!", result.get());
|
||||
}
|
||||
|
||||
assertTrue(jedis.scriptExists(sha1));
|
||||
@Test
|
||||
public void testEvalshaKeyAndArg() {
|
||||
String key = "test";
|
||||
String arg = "3";
|
||||
String script = "redis.call('INCRBY', KEYS[1], ARGV[1]) redis.call('INCRBY', KEYS[1], ARGV[1])";
|
||||
String sha1 = jedis.scriptLoad(script);
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set(key, "0");
|
||||
Response<String> result0 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
|
||||
p.incr(key);
|
||||
Response<String> result1 = p.evalsha(sha1, Arrays.asList(key), Arrays.asList(arg));
|
||||
Response<String> result2 = p.get(key);
|
||||
p.sync();
|
||||
assertTrue(jedis.scriptExists(sha1));
|
||||
|
||||
assertNull(result0.get());
|
||||
assertNull(result1.get());
|
||||
assertEquals("13", result2.get());
|
||||
}
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.set(key, "0");
|
||||
Response<String> result0 = p.evalsha(sha1, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
p.incr(key);
|
||||
Response<String> result1 = p.evalsha(sha1, Arrays.asList(key),
|
||||
Arrays.asList(arg));
|
||||
Response<String> result2 = p.get(key);
|
||||
p.sync();
|
||||
|
||||
assertNull(result0.get());
|
||||
assertNull(result1.get());
|
||||
assertEquals("13", result2.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,86 +19,86 @@ import redis.clients.util.SafeEncoder;
|
||||
public class ProtocolTest extends JedisTestBase {
|
||||
@Test
|
||||
public void buildACommand() throws IOException {
|
||||
PipedInputStream pis = new PipedInputStream();
|
||||
BufferedInputStream bis = new BufferedInputStream(pis);
|
||||
PipedOutputStream pos = new PipedOutputStream(pis);
|
||||
RedisOutputStream ros = new RedisOutputStream(pos);
|
||||
PipedInputStream pis = new PipedInputStream();
|
||||
BufferedInputStream bis = new BufferedInputStream(pis);
|
||||
PipedOutputStream pos = new PipedOutputStream(pis);
|
||||
RedisOutputStream ros = new RedisOutputStream(pos);
|
||||
|
||||
Protocol.sendCommand(ros, Protocol.Command.GET,
|
||||
"SOMEKEY".getBytes(Protocol.CHARSET));
|
||||
ros.flush();
|
||||
pos.close();
|
||||
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
|
||||
Protocol.sendCommand(ros, Protocol.Command.GET,
|
||||
"SOMEKEY".getBytes(Protocol.CHARSET));
|
||||
ros.flush();
|
||||
pos.close();
|
||||
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
|
||||
|
||||
int b;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while ((b = bis.read()) != -1) {
|
||||
sb.append((char) b);
|
||||
}
|
||||
int b;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while ((b = bis.read()) != -1) {
|
||||
sb.append((char) b);
|
||||
}
|
||||
|
||||
assertEquals(expectedCommand, sb.toString());
|
||||
assertEquals(expectedCommand, sb.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bulkReply() {
|
||||
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals(SafeEncoder.encode("foobar"), response);
|
||||
InputStream is = new ByteArrayInputStream("$6\r\nfoobar\r\n".getBytes());
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals(SafeEncoder.encode("foobar"), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fragmentedBulkReply() {
|
||||
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
|
||||
"$30\r\n012345678901234567890123456789\r\n".getBytes());
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis));
|
||||
assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"),
|
||||
response);
|
||||
FragmentedByteArrayInputStream fis = new FragmentedByteArrayInputStream(
|
||||
"$30\r\n012345678901234567890123456789\r\n".getBytes());
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(fis));
|
||||
assertArrayEquals(SafeEncoder.encode("012345678901234567890123456789"),
|
||||
response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullBulkReply() {
|
||||
InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
|
||||
String response = (String) Protocol.read(new RedisInputStream(is));
|
||||
assertEquals(null, response);
|
||||
InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
|
||||
String response = (String) Protocol.read(new RedisInputStream(is));
|
||||
assertEquals(null, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleLineReply() {
|
||||
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals(SafeEncoder.encode("OK"), response);
|
||||
InputStream is = new ByteArrayInputStream("+OK\r\n".getBytes());
|
||||
byte[] response = (byte[]) Protocol.read(new RedisInputStream(is));
|
||||
assertArrayEquals(SafeEncoder.encode("OK"), response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integerReply() {
|
||||
InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
|
||||
long response = (Long) Protocol.read(new RedisInputStream(is));
|
||||
assertEquals(123, response);
|
||||
InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
|
||||
long response = (Long) Protocol.read(new RedisInputStream(is));
|
||||
assertEquals(123, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void multiBulkReply() {
|
||||
InputStream is = new ByteArrayInputStream(
|
||||
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
||||
.getBytes());
|
||||
List<byte[]> response = (List<byte[]>) Protocol
|
||||
.read(new RedisInputStream(is));
|
||||
List<byte[]> expected = new ArrayList<byte[]>();
|
||||
expected.add(SafeEncoder.encode("foo"));
|
||||
expected.add(SafeEncoder.encode("bar"));
|
||||
expected.add(SafeEncoder.encode("Hello"));
|
||||
expected.add(SafeEncoder.encode("World"));
|
||||
InputStream is = new ByteArrayInputStream(
|
||||
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
||||
.getBytes());
|
||||
List<byte[]> response = (List<byte[]>) Protocol
|
||||
.read(new RedisInputStream(is));
|
||||
List<byte[]> expected = new ArrayList<byte[]>();
|
||||
expected.add(SafeEncoder.encode("foo"));
|
||||
expected.add(SafeEncoder.encode("bar"));
|
||||
expected.add(SafeEncoder.encode("Hello"));
|
||||
expected.add(SafeEncoder.encode("World"));
|
||||
|
||||
assertEquals(expected, response);
|
||||
assertEquals(expected, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void nullMultiBulkReply() {
|
||||
InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
|
||||
List<String> response = (List<String>) Protocol
|
||||
.read(new RedisInputStream(is));
|
||||
assertNull(response);
|
||||
InputStream is = new ByteArrayInputStream("*-1\r\n".getBytes());
|
||||
List<String> response = (List<String>) Protocol
|
||||
.read(new RedisInputStream(is));
|
||||
assertNull(response);
|
||||
}
|
||||
}
|
||||
@@ -18,286 +18,288 @@ import redis.clients.util.Sharded;
|
||||
|
||||
public class ShardedJedisTest extends Assert {
|
||||
private static HostAndPort redis1 = HostAndPortUtil.getRedisServers()
|
||||
.get(0);
|
||||
.get(0);
|
||||
private static HostAndPort redis2 = HostAndPortUtil.getRedisServers()
|
||||
.get(1);
|
||||
.get(1);
|
||||
|
||||
private List<String> getKeysDifferentShard(ShardedJedis jedis) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
JedisShardInfo first = jedis.getShardInfo("a0");
|
||||
ret.add("a0");
|
||||
for (int i = 1; i < 100; ++i) {
|
||||
JedisShardInfo actual = jedis.getShardInfo("a" + i);
|
||||
if (actual != first) {
|
||||
ret.add("a" + i);
|
||||
break;
|
||||
List<String> ret = new ArrayList<String>();
|
||||
JedisShardInfo first = jedis.getShardInfo("a0");
|
||||
ret.add("a0");
|
||||
for (int i = 1; i < 100; ++i) {
|
||||
JedisShardInfo actual = jedis.getShardInfo("a" + i);
|
||||
if (actual != first) {
|
||||
ret.add("a" + i);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkSharding() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
|
||||
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
List<String> keys = getKeysDifferentShard(jedis);
|
||||
JedisShardInfo s1 = jedis.getShardInfo(keys.get(0));
|
||||
JedisShardInfo s2 = jedis.getShardInfo(keys.get(1));
|
||||
assertNotSame(s1, s2);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
|
||||
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
List<String> keys = getKeysDifferentShard(jedis);
|
||||
JedisShardInfo s1 = jedis.getShardInfo(keys.get(0));
|
||||
JedisShardInfo s2 = jedis.getShardInfo(keys.get(1));
|
||||
assertNotSame(s1, s2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trySharding() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(), redis1.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
jedis.set("a", "bar");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
jedis.set("b", "bar1");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
jedis.disconnect();
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(),
|
||||
redis1.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
jedis.set("a", "bar");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
jedis.set("b", "bar1");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
jedis.disconnect();
|
||||
|
||||
Jedis j = new Jedis(s1.getHost(), s1.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar", j.get("a"));
|
||||
j.disconnect();
|
||||
Jedis j = new Jedis(s1.getHost(), s1.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar", j.get("a"));
|
||||
j.disconnect();
|
||||
|
||||
j = new Jedis(s2.getHost(), s2.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar1", j.get("b"));
|
||||
j.disconnect();
|
||||
j = new Jedis(s2.getHost(), s2.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar1", j.get("b"));
|
||||
j.disconnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tryShardingWithMurmure() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(), redis1.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
ShardedJedis jedis = new ShardedJedis(shards, Hashing.MURMUR_HASH);
|
||||
jedis.set("a", "bar");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
jedis.set("b", "bar1");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
jedis.disconnect();
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo si = new JedisShardInfo(redis1.getHost(),
|
||||
redis1.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
|
||||
si.setPassword("foobared");
|
||||
shards.add(si);
|
||||
ShardedJedis jedis = new ShardedJedis(shards, Hashing.MURMUR_HASH);
|
||||
jedis.set("a", "bar");
|
||||
JedisShardInfo s1 = jedis.getShardInfo("a");
|
||||
jedis.set("b", "bar1");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("b");
|
||||
jedis.disconnect();
|
||||
|
||||
Jedis j = new Jedis(s1.getHost(), s1.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar", j.get("a"));
|
||||
j.disconnect();
|
||||
Jedis j = new Jedis(s1.getHost(), s1.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar", j.get("a"));
|
||||
j.disconnect();
|
||||
|
||||
j = new Jedis(s2.getHost(), s2.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar1", j.get("b"));
|
||||
j.disconnect();
|
||||
j = new Jedis(s2.getHost(), s2.getPort());
|
||||
j.auth("foobared");
|
||||
assertEquals("bar1", j.get("b"));
|
||||
j.disconnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkKeyTags() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
|
||||
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
|
||||
ShardedJedis jedis = new ShardedJedis(shards,
|
||||
ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
|
||||
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
|
||||
ShardedJedis jedis = new ShardedJedis(shards,
|
||||
ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
|
||||
|
||||
assertEquals(jedis.getKeyTag("foo"), "foo");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}"), "bar");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is
|
||||
// non greedy
|
||||
assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear
|
||||
// anywhere
|
||||
assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear
|
||||
// anywhere
|
||||
assertEquals(jedis.getKeyTag("foo"), "foo");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}"), "bar");
|
||||
assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is
|
||||
// non greedy
|
||||
assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear
|
||||
// anywhere
|
||||
assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear
|
||||
// anywhere
|
||||
|
||||
JedisShardInfo s1 = jedis.getShardInfo("abc{bar}");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("foo{bar}");
|
||||
assertSame(s1, s2);
|
||||
JedisShardInfo s1 = jedis.getShardInfo("abc{bar}");
|
||||
JedisShardInfo s2 = jedis.getShardInfo("foo{bar}");
|
||||
assertSame(s1, s2);
|
||||
|
||||
List<String> keys = getKeysDifferentShard(jedis);
|
||||
JedisShardInfo s3 = jedis.getShardInfo(keys.get(0));
|
||||
JedisShardInfo s4 = jedis.getShardInfo(keys.get(1));
|
||||
assertNotSame(s3, s4);
|
||||
List<String> keys = getKeysDifferentShard(jedis);
|
||||
JedisShardInfo s3 = jedis.getShardInfo(keys.get(0));
|
||||
JedisShardInfo s4 = jedis.getShardInfo(keys.get(1));
|
||||
assertNotSame(s3, s4);
|
||||
|
||||
ShardedJedis jedis2 = new ShardedJedis(shards);
|
||||
ShardedJedis jedis2 = new ShardedJedis(shards);
|
||||
|
||||
assertEquals(jedis2.getKeyTag("foo"), "foo");
|
||||
assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar");
|
||||
assertEquals(jedis2.getKeyTag("foo"), "foo");
|
||||
assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar");
|
||||
|
||||
JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}");
|
||||
JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}");
|
||||
assertNotSame(s5, s6);
|
||||
JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}");
|
||||
JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}");
|
||||
assertNotSame(s5, s6);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shardedPipeline() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
|
||||
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
|
||||
shards.get(0).setPassword("foobared");
|
||||
shards.get(1).setPassword("foobared");
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
|
||||
shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
|
||||
shards.get(0).setPassword("foobared");
|
||||
shards.get(1).setPassword("foobared");
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
|
||||
final List<String> keys = getKeysDifferentShard(jedis);
|
||||
jedis.set(keys.get(0), "a");
|
||||
jedis.set(keys.get(1), "b");
|
||||
final List<String> keys = getKeysDifferentShard(jedis);
|
||||
jedis.set(keys.get(0), "a");
|
||||
jedis.set(keys.get(1), "b");
|
||||
|
||||
assertNotSame(jedis.getShard(keys.get(0)), jedis.getShard(keys.get(1)));
|
||||
assertNotSame(jedis.getShard(keys.get(0)), jedis.getShard(keys.get(1)));
|
||||
|
||||
List<Object> results = jedis.pipelined(new ShardedJedisPipeline() {
|
||||
public void execute() {
|
||||
get(keys.get(0));
|
||||
get(keys.get(1));
|
||||
}
|
||||
});
|
||||
List<Object> results = jedis.pipelined(new ShardedJedisPipeline() {
|
||||
public void execute() {
|
||||
get(keys.get(0));
|
||||
get(keys.get(1));
|
||||
}
|
||||
});
|
||||
|
||||
List<Object> expected = new ArrayList<Object>(2);
|
||||
expected.add(SafeEncoder.encode("a"));
|
||||
expected.add(SafeEncoder.encode("b"));
|
||||
List<Object> expected = new ArrayList<Object>(2);
|
||||
expected.add(SafeEncoder.encode("a"));
|
||||
expected.add(SafeEncoder.encode("b"));
|
||||
|
||||
assertEquals(2, results.size());
|
||||
assertArrayEquals(SafeEncoder.encode("a"), (byte[]) results.get(0));
|
||||
assertArrayEquals(SafeEncoder.encode("b"), (byte[]) results.get(1));
|
||||
assertEquals(2, results.size());
|
||||
assertArrayEquals(SafeEncoder.encode("a"), (byte[]) results.get(0));
|
||||
assertArrayEquals(SafeEncoder.encode("b"), (byte[]) results.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMD5Sharding() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MD5);
|
||||
int shard_6379 = 0;
|
||||
int shard_6380 = 0;
|
||||
int shard_6381 = 0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
switch (jedisShardInfo.getPort()) {
|
||||
case 6379:
|
||||
shard_6379++;
|
||||
break;
|
||||
case 6380:
|
||||
shard_6380++;
|
||||
break;
|
||||
case 6381:
|
||||
shard_6381++;
|
||||
break;
|
||||
default:
|
||||
fail("Attempting to use a non-defined shard!!:"
|
||||
+ jedisShardInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(shard_6379 > 300 && shard_6379 < 400);
|
||||
assertTrue(shard_6380 > 300 && shard_6380 < 400);
|
||||
assertTrue(shard_6381 > 300 && shard_6381 < 400);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MD5);
|
||||
int shard_6379 = 0;
|
||||
int shard_6380 = 0;
|
||||
int shard_6381 = 0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
switch (jedisShardInfo.getPort()) {
|
||||
case 6379:
|
||||
shard_6379++;
|
||||
break;
|
||||
case 6380:
|
||||
shard_6380++;
|
||||
break;
|
||||
case 6381:
|
||||
shard_6381++;
|
||||
break;
|
||||
default:
|
||||
fail("Attempting to use a non-defined shard!!:"
|
||||
+ jedisShardInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(shard_6379 > 300 && shard_6379 < 400);
|
||||
assertTrue(shard_6380 > 300 && shard_6380 < 400);
|
||||
assertTrue(shard_6381 > 300 && shard_6381 < 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMurmurSharding() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
int shard_6379 = 0;
|
||||
int shard_6380 = 0;
|
||||
int shard_6381 = 0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
switch (jedisShardInfo.getPort()) {
|
||||
case 6379:
|
||||
shard_6379++;
|
||||
break;
|
||||
case 6380:
|
||||
shard_6380++;
|
||||
break;
|
||||
case 6381:
|
||||
shard_6381++;
|
||||
break;
|
||||
default:
|
||||
fail("Attempting to use a non-defined shard!!:"
|
||||
+ jedisShardInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(shard_6379 > 300 && shard_6379 < 400);
|
||||
assertTrue(shard_6380 > 300 && shard_6380 < 400);
|
||||
assertTrue(shard_6381 > 300 && shard_6381 < 400);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
int shard_6379 = 0;
|
||||
int shard_6380 = 0;
|
||||
int shard_6381 = 0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
switch (jedisShardInfo.getPort()) {
|
||||
case 6379:
|
||||
shard_6379++;
|
||||
break;
|
||||
case 6380:
|
||||
shard_6380++;
|
||||
break;
|
||||
case 6381:
|
||||
shard_6381++;
|
||||
break;
|
||||
default:
|
||||
fail("Attempting to use a non-defined shard!!:"
|
||||
+ jedisShardInfo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(shard_6379 > 300 && shard_6379 < 400);
|
||||
assertTrue(shard_6380 > 300 && shard_6380 < 400);
|
||||
assertTrue(shard_6381 > 300 && shard_6381 < 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMasterSlaveShardingConsistency() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
|
||||
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
|
||||
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 1));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
|
||||
otherShards, Hashing.MURMUR_HASH);
|
||||
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
|
||||
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 1));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 2));
|
||||
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
|
||||
otherShards, Hashing.MURMUR_HASH);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
|
||||
.toString(i));
|
||||
assertEquals(shards.indexOf(jedisShardInfo), otherShards
|
||||
.indexOf(jedisShardInfo2));
|
||||
}
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
|
||||
.toString(i));
|
||||
assertEquals(shards.indexOf(jedisShardInfo),
|
||||
otherShards.indexOf(jedisShardInfo2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMasterSlaveShardingConsistencyWithShardNaming() {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT,
|
||||
"HOST1:1234"));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1,
|
||||
"HOST2:1234"));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2,
|
||||
"HOST3:1234"));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT,
|
||||
"HOST1:1234"));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1,
|
||||
"HOST2:1234"));
|
||||
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2,
|
||||
"HOST3:1234"));
|
||||
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(
|
||||
shards, Hashing.MURMUR_HASH);
|
||||
|
||||
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
|
||||
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT,
|
||||
"HOST2:1234"));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 1, "HOST3:1234"));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 2, "HOST1:1234"));
|
||||
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
|
||||
otherShards, Hashing.MURMUR_HASH);
|
||||
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
|
||||
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT,
|
||||
"HOST2:1234"));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 1, "HOST3:1234"));
|
||||
otherShards.add(new JedisShardInfo("otherhost",
|
||||
Protocol.DEFAULT_PORT + 2, "HOST1:1234"));
|
||||
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(
|
||||
otherShards, Hashing.MURMUR_HASH);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
|
||||
.toString(i));
|
||||
assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName());
|
||||
}
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer
|
||||
.toString(i));
|
||||
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer
|
||||
.toString(i));
|
||||
assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||
|
||||
public class GetSetBenchmark {
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
private static final int TOTAL_OPERATIONS = 100000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
|
||||
@@ -19,32 +19,33 @@ public class HashingBenchmark {
|
||||
private static final int TOTAL_OPERATIONS = 100000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(), hnp1.getPort());
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort());
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
Collection<Jedis> allShards = jedis.getAllShards();
|
||||
for (Jedis j : allShards) {
|
||||
j.flushAll();
|
||||
}
|
||||
IOException {
|
||||
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
|
||||
JedisShardInfo shard = new JedisShardInfo(hnp1.getHost(),
|
||||
hnp1.getPort());
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort());
|
||||
shard.setPassword("foobared");
|
||||
shards.add(shard);
|
||||
ShardedJedis jedis = new ShardedJedis(shards);
|
||||
Collection<Jedis> allShards = jedis.getAllShards();
|
||||
for (Jedis j : allShards) {
|
||||
j.flushAll();
|
||||
}
|
||||
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
jedis.set(key, "bar" + n);
|
||||
jedis.get(key);
|
||||
}
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
jedis.set(key, "bar" + n);
|
||||
jedis.get(key);
|
||||
}
|
||||
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
jedis.disconnect();
|
||||
jedis.disconnect();
|
||||
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
}
|
||||
}
|
||||
@@ -14,26 +14,26 @@ public class PipelinedGetSetBenchmark {
|
||||
private static final int TOTAL_OPERATIONS = 200000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
IOException {
|
||||
Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
p.set(key, "bar" + n);
|
||||
p.get(key);
|
||||
}
|
||||
p.sync();
|
||||
Pipeline p = jedis.pipelined();
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
p.set(key, "bar" + n);
|
||||
p.get(key);
|
||||
}
|
||||
p.sync();
|
||||
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
jedis.disconnect();
|
||||
jedis.disconnect();
|
||||
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
}
|
||||
}
|
||||
@@ -10,29 +10,29 @@ public class SafeEncoderBenchmark {
|
||||
private static final int TOTAL_OPERATIONS = 10000000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
IOException {
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
SafeEncoder.encode("foo bar!");
|
||||
}
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
SafeEncoder.encode("foo bar!");
|
||||
}
|
||||
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed)
|
||||
+ " ops to build byte[]");
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed)
|
||||
+ " ops to build byte[]");
|
||||
|
||||
begin = Calendar.getInstance().getTimeInMillis();
|
||||
begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
byte[] bytes = "foo bar!".getBytes();
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
SafeEncoder.encode(bytes);
|
||||
}
|
||||
byte[] bytes = "foo bar!".getBytes();
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
SafeEncoder.encode(bytes);
|
||||
}
|
||||
|
||||
elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed)
|
||||
+ " ops to build Strings");
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed)
|
||||
+ " ops to build Strings");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,30 +10,30 @@ public class ShardedBenchmark {
|
||||
private static final int TOTAL_OPERATIONS = 10000000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
IOException {
|
||||
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
long begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
Hashing.MD5.hash(key);
|
||||
}
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
Hashing.MD5.hash(key);
|
||||
}
|
||||
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
long elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " MD5 ops");
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + " MD5 ops");
|
||||
|
||||
begin = Calendar.getInstance().getTimeInMillis();
|
||||
begin = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
Hashing.MURMUR_HASH.hash(key);
|
||||
}
|
||||
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
|
||||
String key = "foo" + n;
|
||||
Hashing.MURMUR_HASH.hash(key);
|
||||
}
|
||||
|
||||
elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
elapsed = Calendar.getInstance().getTimeInMillis() - begin;
|
||||
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed)
|
||||
+ " Murmur ops");
|
||||
System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed)
|
||||
+ " Murmur ops");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,20 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
byte[] bxx = { 0x78, 0x78 };
|
||||
byte[] bnx = { 0x6E, 0x78 };
|
||||
byte[] bxx = { 0x78, 0x78 };
|
||||
byte[] bnx = { 0x6E, 0x78 };
|
||||
byte[] bex = { 0x65, 0x78 };
|
||||
byte[] bpx = { 0x70, 0x78 };
|
||||
long expireSeconds = 2;
|
||||
@@ -22,261 +23,260 @@ public class BinaryValuesCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Before
|
||||
public void startUp() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int n = 0; n < 1000; n++) {
|
||||
sb.append("A");
|
||||
}
|
||||
for (int n = 0; n < 1000; n++) {
|
||||
sb.append("A");
|
||||
}
|
||||
|
||||
binaryValue = sb.toString().getBytes();
|
||||
binaryValue = sb.toString().getBytes();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndGet() {
|
||||
String status = jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
String status = jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
|
||||
assertNull(jedis.get(bbar));
|
||||
assertNull(jedis.get(bbar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNxExAndGet() {
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
|
||||
assertNull(jedis.get(bbar));
|
||||
assertNull(jedis.get(bbar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIfNotExistAndGet() {
|
||||
String status= jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
// nx should fail if value exists
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
assertNull(statusFail);
|
||||
String status = jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
// nx should fail if value exists
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bnx, bex,
|
||||
expireSeconds);
|
||||
assertNull(statusFail);
|
||||
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
|
||||
assertNull(jedis.get(bbar));
|
||||
assertNull(jedis.get(bbar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIfExistAndGet() {
|
||||
String status= jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
// nx should fail if value exists
|
||||
String statusSuccess = jedis.set(bfoo, binaryValue, bxx, bex, expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(statusSuccess));
|
||||
String status = jedis.set(bfoo, binaryValue);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
// nx should fail if value exists
|
||||
String statusSuccess = jedis.set(bfoo, binaryValue, bxx, bex,
|
||||
expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(statusSuccess));
|
||||
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
byte[] value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
|
||||
assertNull(jedis.get(bbar));
|
||||
assertNull(jedis.get(bbar));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setFailIfNotExistAndGet() {
|
||||
// xx should fail if value does NOT exists
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bxx, bex, expireSeconds);
|
||||
assertNull(statusFail);
|
||||
// xx should fail if value does NOT exists
|
||||
String statusFail = jedis.set(bfoo, binaryValue, bxx, bex,
|
||||
expireSeconds);
|
||||
assertNull(statusFail);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndExpireMillis() {
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bpx, expireMillis);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
long ttl = jedis.ttl(bfoo);
|
||||
assertTrue(ttl > 0 && ttl <= expireSeconds);
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bpx, expireMillis);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
long ttl = jedis.ttl(bfoo);
|
||||
assertTrue(ttl > 0 && ttl <= expireSeconds);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void setAndExpire() {
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
long ttl = jedis.ttl(bfoo);
|
||||
assertTrue(ttl > 0 && ttl <= expireSeconds);
|
||||
String status = jedis.set(bfoo, binaryValue, bnx, bex, expireSeconds);
|
||||
assertTrue(Keyword.OK.name().equalsIgnoreCase(status));
|
||||
long ttl = jedis.ttl(bfoo);
|
||||
assertTrue(ttl > 0 && ttl <= expireSeconds);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSet() {
|
||||
byte[] value = jedis.getSet(bfoo, binaryValue);
|
||||
assertNull(value);
|
||||
value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
byte[] value = jedis.getSet(bfoo, binaryValue);
|
||||
assertNull(value);
|
||||
value = jedis.get(bfoo);
|
||||
assertTrue(Arrays.equals(binaryValue, value));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mget() {
|
||||
List<byte[]> values = jedis.mget(bfoo, bbar);
|
||||
List<byte[]> expected = new ArrayList<byte[]>();
|
||||
expected.add(null);
|
||||
expected.add(null);
|
||||
List<byte[]> values = jedis.mget(bfoo, bbar);
|
||||
List<byte[]> expected = new ArrayList<byte[]>();
|
||||
expected.add(null);
|
||||
expected.add(null);
|
||||
|
||||
assertEquals(expected, values);
|
||||
assertEquals(expected, values);
|
||||
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.set(bfoo, binaryValue);
|
||||
|
||||
expected = new ArrayList<byte[]>();
|
||||
expected.add(binaryValue);
|
||||
expected.add(null);
|
||||
values = jedis.mget(bfoo, bbar);
|
||||
expected = new ArrayList<byte[]>();
|
||||
expected.add(binaryValue);
|
||||
expected.add(null);
|
||||
values = jedis.mget(bfoo, bbar);
|
||||
|
||||
assertEquals(expected, values);
|
||||
assertEquals(expected, values);
|
||||
|
||||
jedis.set(bbar, bfoo);
|
||||
jedis.set(bbar, bfoo);
|
||||
|
||||
expected = new ArrayList<byte[]>();
|
||||
expected.add(binaryValue);
|
||||
expected.add(bfoo);
|
||||
values = jedis.mget(bfoo, bbar);
|
||||
expected = new ArrayList<byte[]>();
|
||||
expected.add(binaryValue);
|
||||
expected.add(bfoo);
|
||||
values = jedis.mget(bfoo, bbar);
|
||||
|
||||
assertEquals(expected, values);
|
||||
assertEquals(expected, values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setnx() {
|
||||
long status = jedis.setnx(bfoo, binaryValue);
|
||||
assertEquals(1, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
long status = jedis.setnx(bfoo, binaryValue);
|
||||
assertEquals(1, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
|
||||
status = jedis.setnx(bfoo, bbar);
|
||||
assertEquals(0, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
status = jedis.setnx(bfoo, bbar);
|
||||
assertEquals(0, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setex() {
|
||||
String status = jedis.setex(bfoo, 20, binaryValue);
|
||||
assertEquals(Keyword.OK.name(), status);
|
||||
long ttl = jedis.ttl(bfoo);
|
||||
assertTrue(ttl > 0 && ttl <= 20);
|
||||
String status = jedis.setex(bfoo, 20, binaryValue);
|
||||
assertEquals(Keyword.OK.name(), status);
|
||||
long ttl = jedis.ttl(bfoo);
|
||||
assertTrue(ttl > 0 && ttl <= 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mset() {
|
||||
String status = jedis.mset(bfoo, binaryValue, bbar, bfoo);
|
||||
assertEquals(Keyword.OK.name(), status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||
String status = jedis.mset(bfoo, binaryValue, bbar, bfoo);
|
||||
assertEquals(Keyword.OK.name(), status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void msetnx() {
|
||||
long status = jedis.msetnx(bfoo, binaryValue, bbar, bfoo);
|
||||
assertEquals(1, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||
long status = jedis.msetnx(bfoo, binaryValue, bbar, bfoo);
|
||||
assertEquals(1, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||
|
||||
status = jedis.msetnx(bfoo, bbar, "bar2".getBytes(), "foo2".getBytes());
|
||||
assertEquals(0, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||
status = jedis.msetnx(bfoo, bbar, "bar2".getBytes(), "foo2".getBytes());
|
||||
assertEquals(0, status);
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(bfoo, jedis.get(bbar)));
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void incrWrongValue() {
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.incr(bfoo);
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.incr(bfoo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incr() {
|
||||
long value = jedis.incr(bfoo);
|
||||
assertEquals(1, value);
|
||||
value = jedis.incr(bfoo);
|
||||
assertEquals(2, value);
|
||||
long value = jedis.incr(bfoo);
|
||||
assertEquals(1, value);
|
||||
value = jedis.incr(bfoo);
|
||||
assertEquals(2, value);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void incrByWrongValue() {
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.incrBy(bfoo, 2);
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.incrBy(bfoo, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incrBy() {
|
||||
long value = jedis.incrBy(bfoo, 2);
|
||||
assertEquals(2, value);
|
||||
value = jedis.incrBy(bfoo, 2);
|
||||
assertEquals(4, value);
|
||||
long value = jedis.incrBy(bfoo, 2);
|
||||
assertEquals(2, value);
|
||||
value = jedis.incrBy(bfoo, 2);
|
||||
assertEquals(4, value);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void decrWrongValue() {
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.decr(bfoo);
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.decr(bfoo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decr() {
|
||||
long value = jedis.decr(bfoo);
|
||||
assertEquals(-1, value);
|
||||
value = jedis.decr(bfoo);
|
||||
assertEquals(-2, value);
|
||||
long value = jedis.decr(bfoo);
|
||||
assertEquals(-1, value);
|
||||
value = jedis.decr(bfoo);
|
||||
assertEquals(-2, value);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void decrByWrongValue() {
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.decrBy(bfoo, 2);
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.decrBy(bfoo, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decrBy() {
|
||||
long value = jedis.decrBy(bfoo, 2);
|
||||
assertEquals(-2, value);
|
||||
value = jedis.decrBy(bfoo, 2);
|
||||
assertEquals(-4, value);
|
||||
long value = jedis.decrBy(bfoo, 2);
|
||||
assertEquals(-2, value);
|
||||
value = jedis.decrBy(bfoo, 2);
|
||||
assertEquals(-4, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append() {
|
||||
byte[] first512 = new byte[512];
|
||||
System.arraycopy(binaryValue, 0, first512, 0, 512);
|
||||
long value = jedis.append(bfoo, first512);
|
||||
assertEquals(512, value);
|
||||
assertTrue(Arrays.equals(first512, jedis.get(bfoo)));
|
||||
byte[] first512 = new byte[512];
|
||||
System.arraycopy(binaryValue, 0, first512, 0, 512);
|
||||
long value = jedis.append(bfoo, first512);
|
||||
assertEquals(512, value);
|
||||
assertTrue(Arrays.equals(first512, jedis.get(bfoo)));
|
||||
|
||||
byte[] rest = new byte[binaryValue.length - 512];
|
||||
System.arraycopy(binaryValue, 512, rest, 0, binaryValue.length - 512);
|
||||
value = jedis.append(bfoo, rest);
|
||||
assertEquals(binaryValue.length, value);
|
||||
byte[] rest = new byte[binaryValue.length - 512];
|
||||
System.arraycopy(binaryValue, 512, rest, 0, binaryValue.length - 512);
|
||||
value = jedis.append(bfoo, rest);
|
||||
assertEquals(binaryValue.length, value);
|
||||
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.get(bfoo)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substr() {
|
||||
jedis.set(bfoo, binaryValue);
|
||||
jedis.set(bfoo, binaryValue);
|
||||
|
||||
byte[] first512 = new byte[512];
|
||||
System.arraycopy(binaryValue, 0, first512, 0, 512);
|
||||
byte[] rfirst512 = jedis.substr(bfoo, 0, 511);
|
||||
assertTrue(Arrays.equals(first512, rfirst512));
|
||||
byte[] first512 = new byte[512];
|
||||
System.arraycopy(binaryValue, 0, first512, 0, 512);
|
||||
byte[] rfirst512 = jedis.substr(bfoo, 0, 511);
|
||||
assertTrue(Arrays.equals(first512, rfirst512));
|
||||
|
||||
byte[] last512 = new byte[512];
|
||||
System
|
||||
.arraycopy(binaryValue, binaryValue.length - 512, last512, 0,
|
||||
512);
|
||||
assertTrue(Arrays.equals(last512, jedis.substr(bfoo, -512, -1)));
|
||||
byte[] last512 = new byte[512];
|
||||
System.arraycopy(binaryValue, binaryValue.length - 512, last512, 0, 512);
|
||||
assertTrue(Arrays.equals(last512, jedis.substr(bfoo, -512, -1)));
|
||||
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.substr(bfoo, 0, -1)));
|
||||
assertTrue(Arrays.equals(binaryValue, jedis.substr(bfoo, 0, -1)));
|
||||
|
||||
assertTrue(Arrays.equals(last512, jedis.substr(bfoo,
|
||||
binaryValue.length - 512, 100000)));
|
||||
assertTrue(Arrays.equals(last512,
|
||||
jedis.substr(bfoo, binaryValue.length - 512, 100000)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strlen() {
|
||||
jedis.set(bfoo, binaryValue);
|
||||
assertEquals(binaryValue.length, jedis.strlen(bfoo).intValue());
|
||||
jedis.set(bfoo, binaryValue);
|
||||
assertEquals(binaryValue.length, jedis.strlen(bfoo).intValue());
|
||||
}
|
||||
}
|
||||
@@ -7,87 +7,85 @@ import redis.clients.jedis.BitOP;
|
||||
public class BitCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void setAndgetbit() {
|
||||
boolean bit = jedis.setbit("foo", 0, true);
|
||||
assertEquals(false, bit);
|
||||
boolean bit = jedis.setbit("foo", 0, true);
|
||||
assertEquals(false, bit);
|
||||
|
||||
bit = jedis.getbit("foo", 0);
|
||||
assertEquals(true, bit);
|
||||
bit = jedis.getbit("foo", 0);
|
||||
assertEquals(true, bit);
|
||||
|
||||
boolean bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes());
|
||||
assertFalse(bbit);
|
||||
boolean bbit = jedis.setbit("bfoo".getBytes(), 0, "1".getBytes());
|
||||
assertFalse(bbit);
|
||||
|
||||
bbit = jedis.getbit("bfoo".getBytes(), 0);
|
||||
assertTrue(bbit);
|
||||
bbit = jedis.getbit("bfoo".getBytes(), 0);
|
||||
assertTrue(bbit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAndgetrange() {
|
||||
jedis.set("key1", "Hello World");
|
||||
long reply = jedis.setrange("key1", 6, "Jedis");
|
||||
assertEquals(11, reply);
|
||||
jedis.set("key1", "Hello World");
|
||||
long reply = jedis.setrange("key1", 6, "Jedis");
|
||||
assertEquals(11, reply);
|
||||
|
||||
assertEquals(jedis.get("key1"), "Hello Jedis");
|
||||
assertEquals(jedis.get("key1"), "Hello Jedis");
|
||||
|
||||
assertEquals("Hello", jedis.getrange("key1", 0, 4));
|
||||
assertEquals("Jedis", jedis.getrange("key1", 6, 11));
|
||||
assertEquals("Hello", jedis.getrange("key1", 0, 4));
|
||||
assertEquals("Jedis", jedis.getrange("key1", 6, 11));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitCount() {
|
||||
jedis.del("foo");
|
||||
jedis.del("foo");
|
||||
|
||||
jedis.setbit("foo", 16, true);
|
||||
jedis.setbit("foo", 24, true);
|
||||
jedis.setbit("foo", 40, true);
|
||||
jedis.setbit("foo", 56, true);
|
||||
jedis.setbit("foo", 16, true);
|
||||
jedis.setbit("foo", 24, true);
|
||||
jedis.setbit("foo", 40, true);
|
||||
jedis.setbit("foo", 56, true);
|
||||
|
||||
long c4 = jedis.bitcount("foo");
|
||||
assertEquals(4, c4);
|
||||
long c4 = jedis.bitcount("foo");
|
||||
assertEquals(4, c4);
|
||||
|
||||
long c3 = jedis.bitcount("foo", 2L, 5L);
|
||||
assertEquals(3, c3);
|
||||
long c3 = jedis.bitcount("foo", 2L, 5L);
|
||||
assertEquals(3, c3);
|
||||
|
||||
jedis.del("foo");
|
||||
jedis.del("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitOp()
|
||||
{
|
||||
jedis.set("key1", "\u0060");
|
||||
jedis.set("key2", "\u0044");
|
||||
public void bitOp() {
|
||||
jedis.set("key1", "\u0060");
|
||||
jedis.set("key2", "\u0044");
|
||||
|
||||
jedis.bitop(BitOP.AND, "resultAnd", "key1", "key2");
|
||||
String resultAnd = jedis.get("resultAnd");
|
||||
assertEquals("\u0040", resultAnd);
|
||||
jedis.bitop(BitOP.AND, "resultAnd", "key1", "key2");
|
||||
String resultAnd = jedis.get("resultAnd");
|
||||
assertEquals("\u0040", resultAnd);
|
||||
|
||||
jedis.bitop(BitOP.OR, "resultOr", "key1", "key2");
|
||||
String resultOr = jedis.get("resultOr");
|
||||
assertEquals("\u0064", resultOr);
|
||||
jedis.bitop(BitOP.OR, "resultOr", "key1", "key2");
|
||||
String resultOr = jedis.get("resultOr");
|
||||
assertEquals("\u0064", resultOr);
|
||||
|
||||
jedis.bitop(BitOP.XOR, "resultXor", "key1", "key2");
|
||||
String resultXor = jedis.get("resultXor");
|
||||
assertEquals("\u0024", resultXor);
|
||||
jedis.bitop(BitOP.XOR, "resultXor", "key1", "key2");
|
||||
String resultXor = jedis.get("resultXor");
|
||||
assertEquals("\u0024", resultXor);
|
||||
|
||||
jedis.del("resultAnd");
|
||||
jedis.del("resultOr");
|
||||
jedis.del("resultXor");
|
||||
jedis.del("key1");
|
||||
jedis.del("key2");
|
||||
jedis.del("resultAnd");
|
||||
jedis.del("resultOr");
|
||||
jedis.del("resultXor");
|
||||
jedis.del("key1");
|
||||
jedis.del("key2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bitOpNot()
|
||||
{
|
||||
jedis.del("key");
|
||||
jedis.setbit("key", 0, true);
|
||||
jedis.setbit("key", 4, true);
|
||||
public void bitOpNot() {
|
||||
jedis.del("key");
|
||||
jedis.setbit("key", 0, true);
|
||||
jedis.setbit("key", 4, true);
|
||||
|
||||
jedis.bitop(BitOP.NOT, "resultNot", "key");
|
||||
jedis.bitop(BitOP.NOT, "resultNot", "key");
|
||||
|
||||
String resultNot = jedis.get("resultNot");
|
||||
assertEquals("\u0077", resultNot);
|
||||
String resultNot = jedis.get("resultNot");
|
||||
assertEquals("\u0077", resultNot);
|
||||
|
||||
jedis.del("key");
|
||||
jedis.del("resultNot");
|
||||
jedis.del("key");
|
||||
jedis.del("resultNot");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,42 +37,45 @@ public class ClusterCommandsTest extends JedisTestBase {
|
||||
node1.disconnect();
|
||||
node2.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void removeSlots() throws InterruptedException {
|
||||
//This is to wait for gossip to replicate data.
|
||||
waitForEqualClusterSize();
|
||||
String[] nodes = node1.clusterNodes().split("\n");
|
||||
String node1Id = nodes[0].split(" ")[0];
|
||||
node1.clusterDelSlots(1,2,3,4,5,500);
|
||||
node1.clusterSetSlotNode(5000, node1Id);
|
||||
node1.clusterDelSlots(5000, 10000);
|
||||
node1.clusterDelSlots(6000);
|
||||
node2.clusterDelSlots(6000,1,2,3,4,5,500,5000);
|
||||
try {
|
||||
node2.clusterDelSlots(10000);
|
||||
} catch (JedisDataException jde) {
|
||||
//Do nothing, slot may or may not be assigned depending on gossip
|
||||
}
|
||||
// This is to wait for gossip to replicate data.
|
||||
waitForEqualClusterSize();
|
||||
String[] nodes = node1.clusterNodes().split("\n");
|
||||
String node1Id = nodes[0].split(" ")[0];
|
||||
node1.clusterDelSlots(1, 2, 3, 4, 5, 500);
|
||||
node1.clusterSetSlotNode(5000, node1Id);
|
||||
node1.clusterDelSlots(5000, 10000);
|
||||
node1.clusterDelSlots(6000);
|
||||
node2.clusterDelSlots(6000, 1, 2, 3, 4, 5, 500, 5000);
|
||||
try {
|
||||
node2.clusterDelSlots(10000);
|
||||
} catch (JedisDataException jde) {
|
||||
// Do nothing, slot may or may not be assigned depending on gossip
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForEqualClusterSize() throws InterruptedException {
|
||||
boolean notEqualSize = true;
|
||||
while (notEqualSize) {
|
||||
notEqualSize = getClusterAttribute(node1.clusterInfo(), "cluster_known_nodes") == getClusterAttribute(node2.clusterInfo(), "cluster_size") ? false : true;
|
||||
}
|
||||
boolean notEqualSize = true;
|
||||
while (notEqualSize) {
|
||||
notEqualSize = getClusterAttribute(node1.clusterInfo(),
|
||||
"cluster_known_nodes") == getClusterAttribute(
|
||||
node2.clusterInfo(), "cluster_size") ? false : true;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getClusterAttribute(String clusterInfo, String attributeName) {
|
||||
for (String infoElement: clusterInfo.split("\n")) {
|
||||
if (infoElement.contains(attributeName)) {
|
||||
return Integer.valueOf(infoElement.split(":")[1].trim());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
private static int getClusterAttribute(String clusterInfo,
|
||||
String attributeName) {
|
||||
for (String infoElement : clusterInfo.split("\n")) {
|
||||
if (infoElement.contains(attributeName)) {
|
||||
return Integer.valueOf(infoElement.split(":")[1].trim());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void clusterNodes() {
|
||||
String nodes = node1.clusterNodes();
|
||||
assertTrue(nodes.split("\n").length > 0);
|
||||
|
||||
@@ -11,12 +11,12 @@ public class ConnectionHandlingCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void quit() {
|
||||
assertEquals("OK", jedis.quit());
|
||||
assertEquals("OK", jedis.quit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binary_quit() {
|
||||
BinaryJedis bj = new BinaryJedis(hnp.getHost());
|
||||
assertEquals("OK", bj.quit());
|
||||
BinaryJedis bj = new BinaryJedis(hnp.getHost());
|
||||
assertEquals("OK", bj.quit());
|
||||
}
|
||||
}
|
||||
@@ -61,11 +61,11 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
||||
public void monitor() {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
// sleep 100ms to make sure that monitor thread runs first
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
try {
|
||||
// sleep 100ms to make sure that monitor thread runs first
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
Jedis j = new Jedis("localhost");
|
||||
j.auth("foobared");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -117,10 +117,10 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
||||
resp = jedis.debug(DebugParams.RELOAD());
|
||||
assertNotNull(resp);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void waitReplicas() {
|
||||
Long replicas = jedis.waitReplicas(1, 100);
|
||||
assertEquals(1, replicas.longValue());
|
||||
assertEquals(1, replicas.longValue());
|
||||
}
|
||||
}
|
||||
@@ -309,7 +309,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "b", "b");
|
||||
jedis.hset("foo", "a", "a");
|
||||
jedis.hset("foo", "aa", "aa");
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0, params);
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0,
|
||||
params);
|
||||
|
||||
assertEquals(0, result.getCursor());
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
@@ -324,7 +325,8 @@ public class HashesCommandsTest extends JedisCommandTestBase {
|
||||
jedis.hset("foo", "a" + i, "a" + i);
|
||||
}
|
||||
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0, params);
|
||||
ScanResult<Map.Entry<String, String>> result = jedis.hscan("foo", 0,
|
||||
params);
|
||||
|
||||
assertFalse(result.getResult().isEmpty());
|
||||
}
|
||||
|
||||
@@ -20,77 +20,77 @@ public abstract class JedisCommandTestBase extends JedisTestBase {
|
||||
protected Jedis jedis;
|
||||
|
||||
public JedisCommandTestBase() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.configSet("timeout", "300");
|
||||
jedis.flushAll();
|
||||
jedis = new Jedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.configSet("timeout", "300");
|
||||
jedis.flushAll();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
jedis.disconnect();
|
||||
jedis.disconnect();
|
||||
}
|
||||
|
||||
protected Jedis createJedis() {
|
||||
Jedis j = new Jedis(hnp.getHost(), hnp.getPort());
|
||||
j.connect();
|
||||
j.auth("foobared");
|
||||
j.flushAll();
|
||||
return j;
|
||||
Jedis j = new Jedis(hnp.getHost(), hnp.getPort());
|
||||
j.connect();
|
||||
j.auth("foobared");
|
||||
j.flushAll();
|
||||
return j;
|
||||
}
|
||||
|
||||
protected void assertEquals(List<byte[]> expected, List<byte[]> actual) {
|
||||
assertEquals(expected.size(), actual.size());
|
||||
for (int n = 0; n < expected.size(); n++) {
|
||||
assertArrayEquals(expected.get(n), actual.get(n));
|
||||
}
|
||||
assertEquals(expected.size(), actual.size());
|
||||
for (int n = 0; n < expected.size(); n++) {
|
||||
assertArrayEquals(expected.get(n), actual.get(n));
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertEquals(Set<byte[]> expected, Set<byte[]> actual) {
|
||||
assertEquals(expected.size(), actual.size());
|
||||
Iterator<byte[]> e = expected.iterator();
|
||||
while (e.hasNext()) {
|
||||
byte[] next = e.next();
|
||||
boolean contained = false;
|
||||
for (byte[] element : expected) {
|
||||
if (Arrays.equals(next, element)) {
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if (!contained) {
|
||||
throw new ComparisonFailure("element is missing",
|
||||
Arrays.toString(next), actual.toString());
|
||||
}
|
||||
}
|
||||
assertEquals(expected.size(), actual.size());
|
||||
Iterator<byte[]> e = expected.iterator();
|
||||
while (e.hasNext()) {
|
||||
byte[] next = e.next();
|
||||
boolean contained = false;
|
||||
for (byte[] element : expected) {
|
||||
if (Arrays.equals(next, element)) {
|
||||
contained = true;
|
||||
}
|
||||
}
|
||||
if (!contained) {
|
||||
throw new ComparisonFailure("element is missing",
|
||||
Arrays.toString(next), actual.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean arrayContains(List<byte[]> array, byte[] expected) {
|
||||
for (byte[] a : array) {
|
||||
try {
|
||||
assertArrayEquals(a, expected);
|
||||
return true;
|
||||
} catch (AssertionError e) {
|
||||
for (byte[] a : array) {
|
||||
try {
|
||||
assertArrayEquals(a, expected);
|
||||
return true;
|
||||
} catch (AssertionError e) {
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean setContains(Set<byte[]> set, byte[] expected) {
|
||||
for (byte[] a : set) {
|
||||
try {
|
||||
assertArrayEquals(a, expected);
|
||||
return true;
|
||||
} catch (AssertionError e) {
|
||||
for (byte[] a : set) {
|
||||
try {
|
||||
assertArrayEquals(a, expected);
|
||||
return true;
|
||||
} catch (AssertionError e) {
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,561 +26,559 @@ public class ListCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void rpush() {
|
||||
long size = jedis.rpush("foo", "bar");
|
||||
assertEquals(1, size);
|
||||
size = jedis.rpush("foo", "foo");
|
||||
assertEquals(2, size);
|
||||
size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
|
||||
long size = jedis.rpush("foo", "bar");
|
||||
assertEquals(1, size);
|
||||
size = jedis.rpush("foo", "foo");
|
||||
assertEquals(2, size);
|
||||
size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
|
||||
// Binary
|
||||
long bsize = jedis.rpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
bsize = jedis.rpush(bfoo, bfoo);
|
||||
assertEquals(2, bsize);
|
||||
bsize = jedis.rpush(bfoo, bbar, bfoo);
|
||||
assertEquals(4, bsize);
|
||||
// Binary
|
||||
long bsize = jedis.rpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
bsize = jedis.rpush(bfoo, bfoo);
|
||||
assertEquals(2, bsize);
|
||||
bsize = jedis.rpush(bfoo, bbar, bfoo);
|
||||
assertEquals(4, bsize);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lpush() {
|
||||
long size = jedis.lpush("foo", "bar");
|
||||
assertEquals(1, size);
|
||||
size = jedis.lpush("foo", "foo");
|
||||
assertEquals(2, size);
|
||||
size = jedis.lpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
long size = jedis.lpush("foo", "bar");
|
||||
assertEquals(1, size);
|
||||
size = jedis.lpush("foo", "foo");
|
||||
assertEquals(2, size);
|
||||
size = jedis.lpush("foo", "bar", "foo");
|
||||
assertEquals(4, size);
|
||||
|
||||
// Binary
|
||||
long bsize = jedis.lpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
bsize = jedis.lpush(bfoo, bfoo);
|
||||
assertEquals(2, bsize);
|
||||
bsize = jedis.lpush(bfoo, bbar, bfoo);
|
||||
assertEquals(4, bsize);
|
||||
// Binary
|
||||
long bsize = jedis.lpush(bfoo, bbar);
|
||||
assertEquals(1, bsize);
|
||||
bsize = jedis.lpush(bfoo, bfoo);
|
||||
assertEquals(2, bsize);
|
||||
bsize = jedis.lpush(bfoo, bbar, bfoo);
|
||||
assertEquals(4, bsize);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void llen() {
|
||||
assertEquals(0, jedis.llen("foo").intValue());
|
||||
jedis.lpush("foo", "bar");
|
||||
jedis.lpush("foo", "car");
|
||||
assertEquals(2, jedis.llen("foo").intValue());
|
||||
assertEquals(0, jedis.llen("foo").intValue());
|
||||
jedis.lpush("foo", "bar");
|
||||
jedis.lpush("foo", "car");
|
||||
assertEquals(2, jedis.llen("foo").intValue());
|
||||
|
||||
// Binary
|
||||
assertEquals(0, jedis.llen(bfoo).intValue());
|
||||
jedis.lpush(bfoo, bbar);
|
||||
jedis.lpush(bfoo, bcar);
|
||||
assertEquals(2, jedis.llen(bfoo).intValue());
|
||||
// Binary
|
||||
assertEquals(0, jedis.llen(bfoo).intValue());
|
||||
jedis.lpush(bfoo, bbar);
|
||||
jedis.lpush(bfoo, bcar);
|
||||
assertEquals(2, jedis.llen(bfoo).intValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void llenNotOnList() {
|
||||
try {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.llen("foo");
|
||||
fail("JedisDataException expected");
|
||||
} catch (final JedisDataException e) {
|
||||
}
|
||||
try {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.llen("foo");
|
||||
fail("JedisDataException expected");
|
||||
} catch (final JedisDataException e) {
|
||||
}
|
||||
|
||||
// Binary
|
||||
try {
|
||||
jedis.set(bfoo, bbar);
|
||||
jedis.llen(bfoo);
|
||||
fail("JedisDataException expected");
|
||||
} catch (final JedisDataException e) {
|
||||
}
|
||||
// Binary
|
||||
try {
|
||||
jedis.set(bfoo, bbar);
|
||||
jedis.llen(bfoo);
|
||||
fail("JedisDataException expected");
|
||||
} catch (final JedisDataException e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lrange() {
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
|
||||
List<String> range = jedis.lrange("foo", 0, 2);
|
||||
assertEquals(expected, range);
|
||||
List<String> range = jedis.lrange("foo", 0, 2);
|
||||
assertEquals(expected, range);
|
||||
|
||||
range = jedis.lrange("foo", 0, 20);
|
||||
assertEquals(expected, range);
|
||||
range = jedis.lrange("foo", 0, 20);
|
||||
assertEquals(expected, range);
|
||||
|
||||
expected = new ArrayList<String>();
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
expected = new ArrayList<String>();
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
|
||||
range = jedis.lrange("foo", 1, 2);
|
||||
assertEquals(expected, range);
|
||||
range = jedis.lrange("foo", 1, 2);
|
||||
assertEquals(expected, range);
|
||||
|
||||
expected = new ArrayList<String>();
|
||||
range = jedis.lrange("foo", 2, 1);
|
||||
assertEquals(expected, range);
|
||||
expected = new ArrayList<String>();
|
||||
range = jedis.lrange("foo", 2, 1);
|
||||
assertEquals(expected, range);
|
||||
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
|
||||
List<byte[]> brange = jedis.lrange(bfoo, 0, 2);
|
||||
assertEquals(bexpected, brange);
|
||||
List<byte[]> brange = jedis.lrange(bfoo, 0, 2);
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
brange = jedis.lrange(bfoo, 0, 20);
|
||||
assertEquals(bexpected, brange);
|
||||
brange = jedis.lrange(bfoo, 0, 20);
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
|
||||
brange = jedis.lrange(bfoo, 1, 2);
|
||||
assertEquals(bexpected, brange);
|
||||
brange = jedis.lrange(bfoo, 1, 2);
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
bexpected = new ArrayList<byte[]>();
|
||||
brange = jedis.lrange(bfoo, 2, 1);
|
||||
assertEquals(bexpected, brange);
|
||||
bexpected = new ArrayList<byte[]>();
|
||||
brange = jedis.lrange(bfoo, 2, 1);
|
||||
assertEquals(bexpected, brange);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ltrim() {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
String status = jedis.ltrim("foo", 0, 1);
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
String status = jedis.ltrim("foo", 0, 1);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("2");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("2");
|
||||
|
||||
assertEquals("OK", status);
|
||||
assertEquals(2, jedis.llen("foo").intValue());
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
||||
assertEquals("OK", status);
|
||||
assertEquals(2, jedis.llen("foo").intValue());
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
String bstatus = jedis.ltrim(bfoo, 0, 1);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
String bstatus = jedis.ltrim(bfoo, 0, 1);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(b2);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(b2);
|
||||
|
||||
assertEquals("OK", bstatus);
|
||||
assertEquals(2, jedis.llen(bfoo).intValue());
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 100));
|
||||
assertEquals("OK", bstatus);
|
||||
assertEquals(2, jedis.llen(bfoo).intValue());
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 100));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lindex() {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("bar");
|
||||
expected.add("1");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("bar");
|
||||
expected.add("1");
|
||||
|
||||
String status = jedis.lset("foo", 1, "bar");
|
||||
String status = jedis.lset("foo", 1, "bar");
|
||||
|
||||
assertEquals("OK", status);
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
||||
assertEquals("OK", status);
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 100));
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(bbar);
|
||||
bexpected.add(b1);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(bbar);
|
||||
bexpected.add(b1);
|
||||
|
||||
String bstatus = jedis.lset(bfoo, 1, bbar);
|
||||
String bstatus = jedis.lset(bfoo, 1, bbar);
|
||||
|
||||
assertEquals("OK", bstatus);
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 100));
|
||||
assertEquals("OK", bstatus);
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lset() {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
|
||||
assertEquals("3", jedis.lindex("foo", 0));
|
||||
assertEquals(null, jedis.lindex("foo", 100));
|
||||
assertEquals("3", jedis.lindex("foo", 0));
|
||||
assertEquals(null, jedis.lindex("foo", 100));
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
|
||||
assertArrayEquals(b3, jedis.lindex(bfoo, 0));
|
||||
assertEquals(null, jedis.lindex(bfoo, 100));
|
||||
assertArrayEquals(b3, jedis.lindex(bfoo, 0));
|
||||
assertEquals(null, jedis.lindex(bfoo, 100));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lrem() {
|
||||
jedis.lpush("foo", "hello");
|
||||
jedis.lpush("foo", "hello");
|
||||
jedis.lpush("foo", "x");
|
||||
jedis.lpush("foo", "hello");
|
||||
jedis.lpush("foo", "c");
|
||||
jedis.lpush("foo", "b");
|
||||
jedis.lpush("foo", "a");
|
||||
jedis.lpush("foo", "hello");
|
||||
jedis.lpush("foo", "hello");
|
||||
jedis.lpush("foo", "x");
|
||||
jedis.lpush("foo", "hello");
|
||||
jedis.lpush("foo", "c");
|
||||
jedis.lpush("foo", "b");
|
||||
jedis.lpush("foo", "a");
|
||||
|
||||
long count = jedis.lrem("foo", -2, "hello");
|
||||
long count = jedis.lrem("foo", -2, "hello");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
expected.add("hello");
|
||||
expected.add("x");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
expected.add("hello");
|
||||
expected.add("x");
|
||||
|
||||
assertEquals(2, count);
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||
assertEquals(0, jedis.lrem("bar", 100, "foo").intValue());
|
||||
assertEquals(2, count);
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||
assertEquals(0, jedis.lrem("bar", 100, "foo").intValue());
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, bhello);
|
||||
jedis.lpush(bfoo, bhello);
|
||||
jedis.lpush(bfoo, bx);
|
||||
jedis.lpush(bfoo, bhello);
|
||||
jedis.lpush(bfoo, bC);
|
||||
jedis.lpush(bfoo, bB);
|
||||
jedis.lpush(bfoo, bA);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, bhello);
|
||||
jedis.lpush(bfoo, bhello);
|
||||
jedis.lpush(bfoo, bx);
|
||||
jedis.lpush(bfoo, bhello);
|
||||
jedis.lpush(bfoo, bC);
|
||||
jedis.lpush(bfoo, bB);
|
||||
jedis.lpush(bfoo, bA);
|
||||
|
||||
long bcount = jedis.lrem(bfoo, -2, bhello);
|
||||
long bcount = jedis.lrem(bfoo, -2, bhello);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
bexpected.add(bhello);
|
||||
bexpected.add(bx);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
bexpected.add(bhello);
|
||||
bexpected.add(bx);
|
||||
|
||||
assertEquals(2, bcount);
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||
assertEquals(0, jedis.lrem(bbar, 100, bfoo).intValue());
|
||||
assertEquals(2, bcount);
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||
assertEquals(0, jedis.lrem(bbar, 100, bfoo).intValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lpop() {
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
|
||||
String element = jedis.lpop("foo");
|
||||
assertEquals("a", element);
|
||||
String element = jedis.lpop("foo");
|
||||
assertEquals("a", element);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||
jedis.lpop("foo");
|
||||
jedis.lpop("foo");
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||
jedis.lpop("foo");
|
||||
jedis.lpop("foo");
|
||||
|
||||
element = jedis.lpop("foo");
|
||||
assertEquals(null, element);
|
||||
element = jedis.lpop("foo");
|
||||
assertEquals(null, element);
|
||||
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
|
||||
byte[] belement = jedis.lpop(bfoo);
|
||||
assertArrayEquals(bA, belement);
|
||||
byte[] belement = jedis.lpop(bfoo);
|
||||
assertArrayEquals(bA, belement);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bB);
|
||||
bexpected.add(bC);
|
||||
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||
jedis.lpop(bfoo);
|
||||
jedis.lpop(bfoo);
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||
jedis.lpop(bfoo);
|
||||
jedis.lpop(bfoo);
|
||||
|
||||
belement = jedis.lpop(bfoo);
|
||||
assertEquals(null, belement);
|
||||
belement = jedis.lpop(bfoo);
|
||||
assertEquals(null, belement);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpop() {
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
|
||||
String element = jedis.rpop("foo");
|
||||
assertEquals("c", element);
|
||||
String element = jedis.rpop("foo");
|
||||
assertEquals("c", element);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||
jedis.rpop("foo");
|
||||
jedis.rpop("foo");
|
||||
assertEquals(expected, jedis.lrange("foo", 0, 1000));
|
||||
jedis.rpop("foo");
|
||||
jedis.rpop("foo");
|
||||
|
||||
element = jedis.rpop("foo");
|
||||
assertEquals(null, element);
|
||||
element = jedis.rpop("foo");
|
||||
assertEquals(null, element);
|
||||
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
|
||||
byte[] belement = jedis.rpop(bfoo);
|
||||
assertArrayEquals(bC, belement);
|
||||
byte[] belement = jedis.rpop(bfoo);
|
||||
assertArrayEquals(bC, belement);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||
jedis.rpop(bfoo);
|
||||
jedis.rpop(bfoo);
|
||||
assertEquals(bexpected, jedis.lrange(bfoo, 0, 1000));
|
||||
jedis.rpop(bfoo);
|
||||
jedis.rpop(bfoo);
|
||||
|
||||
belement = jedis.rpop(bfoo);
|
||||
assertEquals(null, belement);
|
||||
belement = jedis.rpop(bfoo);
|
||||
assertEquals(null, belement);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpoplpush() {
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
jedis.rpush("foo", "a");
|
||||
jedis.rpush("foo", "b");
|
||||
jedis.rpush("foo", "c");
|
||||
|
||||
jedis.rpush("dst", "foo");
|
||||
jedis.rpush("dst", "bar");
|
||||
jedis.rpush("dst", "foo");
|
||||
jedis.rpush("dst", "bar");
|
||||
|
||||
String element = jedis.rpoplpush("foo", "dst");
|
||||
String element = jedis.rpoplpush("foo", "dst");
|
||||
|
||||
assertEquals("c", element);
|
||||
assertEquals("c", element);
|
||||
|
||||
List<String> srcExpected = new ArrayList<String>();
|
||||
srcExpected.add("a");
|
||||
srcExpected.add("b");
|
||||
List<String> srcExpected = new ArrayList<String>();
|
||||
srcExpected.add("a");
|
||||
srcExpected.add("b");
|
||||
|
||||
List<String> dstExpected = new ArrayList<String>();
|
||||
dstExpected.add("c");
|
||||
dstExpected.add("foo");
|
||||
dstExpected.add("bar");
|
||||
List<String> dstExpected = new ArrayList<String>();
|
||||
dstExpected.add("c");
|
||||
dstExpected.add("foo");
|
||||
dstExpected.add("bar");
|
||||
|
||||
assertEquals(srcExpected, jedis.lrange("foo", 0, 1000));
|
||||
assertEquals(dstExpected, jedis.lrange("dst", 0, 1000));
|
||||
assertEquals(srcExpected, jedis.lrange("foo", 0, 1000));
|
||||
assertEquals(dstExpected, jedis.lrange("dst", 0, 1000));
|
||||
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
// Binary
|
||||
jedis.rpush(bfoo, bA);
|
||||
jedis.rpush(bfoo, bB);
|
||||
jedis.rpush(bfoo, bC);
|
||||
|
||||
jedis.rpush(bdst, bfoo);
|
||||
jedis.rpush(bdst, bbar);
|
||||
jedis.rpush(bdst, bfoo);
|
||||
jedis.rpush(bdst, bbar);
|
||||
|
||||
byte[] belement = jedis.rpoplpush(bfoo, bdst);
|
||||
byte[] belement = jedis.rpoplpush(bfoo, bdst);
|
||||
|
||||
assertArrayEquals(bC, belement);
|
||||
assertArrayEquals(bC, belement);
|
||||
|
||||
List<byte[]> bsrcExpected = new ArrayList<byte[]>();
|
||||
bsrcExpected.add(bA);
|
||||
bsrcExpected.add(bB);
|
||||
List<byte[]> bsrcExpected = new ArrayList<byte[]>();
|
||||
bsrcExpected.add(bA);
|
||||
bsrcExpected.add(bB);
|
||||
|
||||
List<byte[]> bdstExpected = new ArrayList<byte[]>();
|
||||
bdstExpected.add(bC);
|
||||
bdstExpected.add(bfoo);
|
||||
bdstExpected.add(bbar);
|
||||
List<byte[]> bdstExpected = new ArrayList<byte[]>();
|
||||
bdstExpected.add(bC);
|
||||
bdstExpected.add(bfoo);
|
||||
bdstExpected.add(bbar);
|
||||
|
||||
assertEquals(bsrcExpected, jedis.lrange(bfoo, 0, 1000));
|
||||
assertEquals(bdstExpected, jedis.lrange(bdst, 0, 1000));
|
||||
assertEquals(bsrcExpected, jedis.lrange(bfoo, 0, 1000));
|
||||
assertEquals(bdstExpected, jedis.lrange(bdst, 0, 1000));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blpop() throws InterruptedException {
|
||||
List<String> result = jedis.blpop(1, "foo");
|
||||
assertNull(result);
|
||||
List<String> result = jedis.blpop(1, "foo");
|
||||
assertNull(result);
|
||||
|
||||
jedis.lpush("foo", "bar");
|
||||
result = jedis.blpop(1, "foo");
|
||||
jedis.lpush("foo", "bar");
|
||||
result = jedis.blpop(1, "foo");
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("foo", result.get(0));
|
||||
assertEquals("bar", result.get(1));
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("foo", result.get(0));
|
||||
assertEquals("bar", result.get(1));
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, bbar);
|
||||
List<byte[]> bresult = jedis.blpop(1, bfoo);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, bbar);
|
||||
List<byte[]> bresult = jedis.blpop(1, bfoo);
|
||||
|
||||
assertNotNull(bresult);
|
||||
assertEquals(2, bresult.size());
|
||||
assertArrayEquals(bfoo, bresult.get(0));
|
||||
assertArrayEquals(bbar, bresult.get(1));
|
||||
assertNotNull(bresult);
|
||||
assertEquals(2, bresult.size());
|
||||
assertArrayEquals(bfoo, bresult.get(0));
|
||||
assertArrayEquals(bbar, bresult.get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brpop() throws InterruptedException {
|
||||
List<String> result = jedis.brpop(1, "foo");
|
||||
assertNull(result);
|
||||
List<String> result = jedis.brpop(1, "foo");
|
||||
assertNull(result);
|
||||
|
||||
jedis.lpush("foo", "bar");
|
||||
result = jedis.brpop(1, "foo");
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("foo", result.get(0));
|
||||
assertEquals("bar", result.get(1));
|
||||
|
||||
jedis.lpush("foo", "bar");
|
||||
result = jedis.brpop(1, "foo");
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("foo", result.get(0));
|
||||
assertEquals("bar", result.get(1));
|
||||
// Binary
|
||||
|
||||
// Binary
|
||||
|
||||
jedis.lpush(bfoo, bbar);
|
||||
List<byte[]> bresult = jedis.brpop(1, bfoo);
|
||||
assertNotNull(bresult);
|
||||
assertEquals(2, bresult.size());
|
||||
assertArrayEquals(bfoo, bresult.get(0));
|
||||
assertArrayEquals(bbar, bresult.get(1));
|
||||
jedis.lpush(bfoo, bbar);
|
||||
List<byte[]> bresult = jedis.brpop(1, bfoo);
|
||||
assertNotNull(bresult);
|
||||
assertEquals(2, bresult.size());
|
||||
assertArrayEquals(bfoo, bresult.get(0));
|
||||
assertArrayEquals(bbar, bresult.get(1));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lpushx() {
|
||||
long status = jedis.lpushx("foo", "bar");
|
||||
assertEquals(0, status);
|
||||
long status = jedis.lpushx("foo", "bar");
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.lpushx("foo", "b");
|
||||
assertEquals(2, status);
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.lpushx("foo", "b");
|
||||
assertEquals(2, status);
|
||||
|
||||
// Binary
|
||||
long bstatus = jedis.lpushx(bfoo, bbar);
|
||||
assertEquals(0, bstatus);
|
||||
// Binary
|
||||
long bstatus = jedis.lpushx(bfoo, bbar);
|
||||
assertEquals(0, bstatus);
|
||||
|
||||
jedis.lpush(bfoo, bA);
|
||||
bstatus = jedis.lpushx(bfoo, bB);
|
||||
assertEquals(2, bstatus);
|
||||
jedis.lpush(bfoo, bA);
|
||||
bstatus = jedis.lpushx(bfoo, bB);
|
||||
assertEquals(2, bstatus);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpushx() {
|
||||
long status = jedis.rpushx("foo", "bar");
|
||||
assertEquals(0, status);
|
||||
long status = jedis.rpushx("foo", "bar");
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.rpushx("foo", "b");
|
||||
assertEquals(2, status);
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.rpushx("foo", "b");
|
||||
assertEquals(2, status);
|
||||
|
||||
// Binary
|
||||
long bstatus = jedis.rpushx(bfoo, bbar);
|
||||
assertEquals(0, bstatus);
|
||||
// Binary
|
||||
long bstatus = jedis.rpushx(bfoo, bbar);
|
||||
assertEquals(0, bstatus);
|
||||
|
||||
jedis.lpush(bfoo, bA);
|
||||
bstatus = jedis.rpushx(bfoo, bB);
|
||||
assertEquals(2, bstatus);
|
||||
jedis.lpush(bfoo, bA);
|
||||
bstatus = jedis.rpushx(bfoo, bB);
|
||||
assertEquals(2, bstatus);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linsert() {
|
||||
long status = jedis.linsert("foo", Client.LIST_POSITION.BEFORE, "bar",
|
||||
"car");
|
||||
assertEquals(0, status);
|
||||
long status = jedis.linsert("foo", Client.LIST_POSITION.BEFORE, "bar",
|
||||
"car");
|
||||
assertEquals(0, status);
|
||||
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.linsert("foo", Client.LIST_POSITION.AFTER, "a", "b");
|
||||
assertEquals(2, status);
|
||||
jedis.lpush("foo", "a");
|
||||
status = jedis.linsert("foo", Client.LIST_POSITION.AFTER, "a", "b");
|
||||
assertEquals(2, status);
|
||||
|
||||
List<String> actual = jedis.lrange("foo", 0, 100);
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
List<String> actual = jedis.lrange("foo", 0, 100);
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
|
||||
assertEquals(expected, actual);
|
||||
assertEquals(expected, actual);
|
||||
|
||||
status = jedis
|
||||
.linsert("foo", Client.LIST_POSITION.BEFORE, "bar", "car");
|
||||
assertEquals(-1, status);
|
||||
status = jedis
|
||||
.linsert("foo", Client.LIST_POSITION.BEFORE, "bar", "car");
|
||||
assertEquals(-1, status);
|
||||
|
||||
// Binary
|
||||
long bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar,
|
||||
bcar);
|
||||
assertEquals(0, bstatus);
|
||||
// Binary
|
||||
long bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar,
|
||||
bcar);
|
||||
assertEquals(0, bstatus);
|
||||
|
||||
jedis.lpush(bfoo, bA);
|
||||
bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.AFTER, bA, bB);
|
||||
assertEquals(2, bstatus);
|
||||
jedis.lpush(bfoo, bA);
|
||||
bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.AFTER, bA, bB);
|
||||
assertEquals(2, bstatus);
|
||||
|
||||
List<byte[]> bactual = jedis.lrange(bfoo, 0, 100);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
List<byte[]> bactual = jedis.lrange(bfoo, 0, 100);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bA);
|
||||
bexpected.add(bB);
|
||||
|
||||
assertEquals(bexpected, bactual);
|
||||
assertEquals(bexpected, bactual);
|
||||
|
||||
bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, bcar);
|
||||
assertEquals(-1, bstatus);
|
||||
bstatus = jedis.linsert(bfoo, Client.LIST_POSITION.BEFORE, bbar, bcar);
|
||||
assertEquals(-1, bstatus);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void brpoplpush() {
|
||||
(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Jedis j = createJedis();
|
||||
j.lpush("foo", "a");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
})).start();
|
||||
(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Jedis j = createJedis();
|
||||
j.lpush("foo", "a");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
})).start();
|
||||
|
||||
String element = jedis.brpoplpush("foo", "bar", 0);
|
||||
String element = jedis.brpoplpush("foo", "bar", 0);
|
||||
|
||||
assertEquals("a", element);
|
||||
assertEquals(1, jedis.llen("bar").longValue());
|
||||
assertEquals("a", jedis.lrange("bar", 0, -1).get(0));
|
||||
assertEquals("a", element);
|
||||
assertEquals(1, jedis.llen("bar").longValue());
|
||||
assertEquals("a", jedis.lrange("bar", 0, -1).get(0));
|
||||
|
||||
(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Jedis j = createJedis();
|
||||
j.lpush("foo", "a");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
})).start();
|
||||
(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Jedis j = createJedis();
|
||||
j.lpush("foo", "a");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
})).start();
|
||||
|
||||
byte[] brpoplpush = jedis.brpoplpush("foo".getBytes(),
|
||||
"bar".getBytes(), 0);
|
||||
byte[] brpoplpush = jedis.brpoplpush("foo".getBytes(),
|
||||
"bar".getBytes(), 0);
|
||||
|
||||
assertTrue(Arrays.equals("a".getBytes(), brpoplpush));
|
||||
assertEquals(1, jedis.llen("bar").longValue());
|
||||
assertEquals("a", jedis.lrange("bar", 0, -1).get(0));
|
||||
assertTrue(Arrays.equals("a".getBytes(), brpoplpush));
|
||||
assertEquals(1, jedis.llen("bar").longValue());
|
||||
assertEquals("a", jedis.lrange("bar", 0, -1).get(0));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void subscribe() throws InterruptedException {
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
@@ -43,8 +43,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
assertEquals("foo", channel);
|
||||
assertEquals(1, subscribedChannels);
|
||||
|
||||
//now that I'm subscribed... publish
|
||||
|
||||
// now that I'm subscribed... publish
|
||||
publishOne("foo", "exit");
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
publishOne(pattern.replace("*", "123"), "exit");
|
||||
publishOne(pattern.replace("*", "123"), "exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
@@ -383,7 +383,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
assertTrue(Arrays.equals(SafeEncoder.encode("foo.*"), pattern));
|
||||
assertEquals(1, subscribedChannels);
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "bar"), "exit");
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "bar"),
|
||||
"exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
@@ -416,7 +417,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"), "exit");
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
||||
"exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
@@ -439,8 +441,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
public void onSubscribe(byte[] channel, int subscribedChannels) {
|
||||
publishOne(SafeEncoder.encode(channel), "exit");
|
||||
|
||||
if(!SafeEncoder.encode(channel).equals("bar")) {
|
||||
|
||||
if (!SafeEncoder.encode(channel).equals("bar")) {
|
||||
this.subscribe(SafeEncoder.encode("bar"));
|
||||
this.psubscribe(SafeEncoder.encode("bar.*"));
|
||||
}
|
||||
@@ -450,7 +452,8 @@ public class PublishSubscribeCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
|
||||
public void onPSubscribe(byte[] pattern, int subscribedChannels) {
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"), "exit");
|
||||
publishOne(SafeEncoder.encode(pattern).replace("*", "123"),
|
||||
"exit");
|
||||
}
|
||||
|
||||
public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
|
||||
|
||||
@@ -33,31 +33,33 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
assertEquals("second", response.get(3));
|
||||
assertEquals("third", response.get(4));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void evalMultiBulkWithBinaryJedis() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}";
|
||||
List<byte[]> keys = new ArrayList<byte[]>();
|
||||
keys.add("key1".getBytes());
|
||||
keys.add("key2".getBytes());
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2],ARGV[3]}";
|
||||
List<byte[]> keys = new ArrayList<byte[]>();
|
||||
keys.add("key1".getBytes());
|
||||
keys.add("key2".getBytes());
|
||||
|
||||
List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add("first".getBytes());
|
||||
args.add("second".getBytes());
|
||||
args.add("third".getBytes());
|
||||
List<byte[]> args = new ArrayList<byte[]>();
|
||||
args.add("first".getBytes());
|
||||
args.add("second".getBytes());
|
||||
args.add("third".getBytes());
|
||||
|
||||
BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(), 500);
|
||||
binaryJedis.connect();
|
||||
binaryJedis.auth("foobared");
|
||||
|
||||
List<byte[]> responses = (List<byte[]>) binaryJedis.eval(script.getBytes(), keys, args);
|
||||
assertEquals(5, responses.size());
|
||||
assertEquals("key1", new String(responses.get(0)));
|
||||
assertEquals("key2", new String(responses.get(1)));
|
||||
assertEquals("first", new String(responses.get(2)));
|
||||
assertEquals("second", new String(responses.get(3)));
|
||||
assertEquals("third", new String(responses.get(4)));
|
||||
BinaryJedis binaryJedis = new BinaryJedis(hnp.getHost(), hnp.getPort(),
|
||||
500);
|
||||
binaryJedis.connect();
|
||||
binaryJedis.auth("foobared");
|
||||
|
||||
List<byte[]> responses = (List<byte[]>) binaryJedis.eval(
|
||||
script.getBytes(), keys, args);
|
||||
assertEquals(5, responses.size());
|
||||
assertEquals("key1", new String(responses.get(0)));
|
||||
assertEquals("key2", new String(responses.get(1)));
|
||||
assertEquals("first", new String(responses.get(2)));
|
||||
assertEquals("second", new String(responses.get(3)));
|
||||
assertEquals("third", new String(responses.get(4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -166,26 +168,27 @@ public class ScriptingCommandsTest extends JedisCommandTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptEvalReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
List<String> results = (List<String>) jedis.eval(script, 2, "key1", "key2", "1", "2");
|
||||
assertEquals(results.get(0), "key1");
|
||||
assertEquals(results.get(1), "key2");
|
||||
assertEquals(results.get(2), "1");
|
||||
assertEquals(results.get(3), "2");
|
||||
}
|
||||
@Test
|
||||
public void scriptEvalReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
List<String> results = (List<String>) jedis.eval(script, 2, "key1",
|
||||
"key2", "1", "2");
|
||||
assertEquals(results.get(0), "key1");
|
||||
assertEquals(results.get(1), "key2");
|
||||
assertEquals(results.get(2), "1");
|
||||
assertEquals(results.get(3), "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scriptEvalShaReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
String sha = jedis.scriptLoad(script);
|
||||
List<String> results = (List<String>) jedis.evalsha(sha, 2, "key1", "key2", "1", "2");
|
||||
assertEquals(results.get(0), "key1");
|
||||
assertEquals(results.get(1), "key2");
|
||||
assertEquals(results.get(2), "1");
|
||||
assertEquals(results.get(3), "2");
|
||||
@Test
|
||||
public void scriptEvalShaReturnNullValues() {
|
||||
String script = "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}";
|
||||
String sha = jedis.scriptLoad(script);
|
||||
List<String> results = (List<String>) jedis.evalsha(sha, 2, "key1",
|
||||
"key2", "1", "2");
|
||||
assertEquals(results.get(0), "key1");
|
||||
assertEquals(results.get(1), "key2");
|
||||
assertEquals(results.get(2), "1");
|
||||
assertEquals(results.get(3), "2");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -22,443 +21,442 @@ public class SetCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void sadd() {
|
||||
long status = jedis.sadd("foo", "a");
|
||||
assertEquals(1, status);
|
||||
long status = jedis.sadd("foo", "a");
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.sadd("foo", "a");
|
||||
assertEquals(0, status);
|
||||
status = jedis.sadd("foo", "a");
|
||||
assertEquals(0, status);
|
||||
|
||||
long bstatus = jedis.sadd(bfoo, ba);
|
||||
assertEquals(1, bstatus);
|
||||
long bstatus = jedis.sadd(bfoo, ba);
|
||||
assertEquals(1, bstatus);
|
||||
|
||||
bstatus = jedis.sadd(bfoo, ba);
|
||||
assertEquals(0, bstatus);
|
||||
bstatus = jedis.sadd(bfoo, ba);
|
||||
assertEquals(0, bstatus);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smembers() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
|
||||
Set<String> members = jedis.smembers("foo");
|
||||
Set<String> members = jedis.smembers("foo");
|
||||
|
||||
assertEquals(expected, members);
|
||||
assertEquals(expected, members);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(ba);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(ba);
|
||||
|
||||
Set<byte[]> bmembers = jedis.smembers(bfoo);
|
||||
Set<byte[]> bmembers = jedis.smembers(bfoo);
|
||||
|
||||
assertEquals(bexpected, bmembers);
|
||||
assertEquals(bexpected, bmembers);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void srem() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
long status = jedis.srem("foo", "a");
|
||||
long status = jedis.srem("foo", "a");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("b");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("b");
|
||||
|
||||
assertEquals(1, status);
|
||||
assertEquals(expected, jedis.smembers("foo"));
|
||||
assertEquals(1, status);
|
||||
assertEquals(expected, jedis.smembers("foo"));
|
||||
|
||||
status = jedis.srem("foo", "bar");
|
||||
status = jedis.srem("foo", "bar");
|
||||
|
||||
assertEquals(0, status);
|
||||
assertEquals(0, status);
|
||||
|
||||
// Binary
|
||||
// Binary
|
||||
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
long bstatus = jedis.srem(bfoo, ba);
|
||||
long bstatus = jedis.srem(bfoo, ba);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
|
||||
assertEquals(1, bstatus);
|
||||
assertEquals(bexpected, jedis.smembers(bfoo));
|
||||
assertEquals(1, bstatus);
|
||||
assertEquals(bexpected, jedis.smembers(bfoo));
|
||||
|
||||
bstatus = jedis.srem(bfoo, bbar);
|
||||
bstatus = jedis.srem(bfoo, bbar);
|
||||
|
||||
assertEquals(0, bstatus);
|
||||
assertEquals(0, bstatus);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spop() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
String member = jedis.spop("foo");
|
||||
String member = jedis.spop("foo");
|
||||
|
||||
assertTrue("a".equals(member) || "b".equals(member));
|
||||
assertEquals(1, jedis.smembers("foo").size());
|
||||
assertTrue("a".equals(member) || "b".equals(member));
|
||||
assertEquals(1, jedis.smembers("foo").size());
|
||||
|
||||
member = jedis.spop("bar");
|
||||
assertNull(member);
|
||||
member = jedis.spop("bar");
|
||||
assertNull(member);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
byte[] bmember = jedis.spop(bfoo);
|
||||
byte[] bmember = jedis.spop(bfoo);
|
||||
|
||||
assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
|
||||
assertEquals(1, jedis.smembers(bfoo).size());
|
||||
assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
|
||||
assertEquals(1, jedis.smembers(bfoo).size());
|
||||
|
||||
bmember = jedis.spop(bbar);
|
||||
assertNull(bmember);
|
||||
bmember = jedis.spop(bbar);
|
||||
assertNull(bmember);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smove() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
long status = jedis.smove("foo", "bar", "a");
|
||||
long status = jedis.smove("foo", "bar", "a");
|
||||
|
||||
Set<String> expectedSrc = new HashSet<String>();
|
||||
expectedSrc.add("b");
|
||||
Set<String> expectedSrc = new HashSet<String>();
|
||||
expectedSrc.add("b");
|
||||
|
||||
Set<String> expectedDst = new HashSet<String>();
|
||||
expectedDst.add("c");
|
||||
expectedDst.add("a");
|
||||
Set<String> expectedDst = new HashSet<String>();
|
||||
expectedDst.add("c");
|
||||
expectedDst.add("a");
|
||||
|
||||
assertEquals(status, 1);
|
||||
assertEquals(expectedSrc, jedis.smembers("foo"));
|
||||
assertEquals(expectedDst, jedis.smembers("bar"));
|
||||
assertEquals(status, 1);
|
||||
assertEquals(expectedSrc, jedis.smembers("foo"));
|
||||
assertEquals(expectedDst, jedis.smembers("bar"));
|
||||
|
||||
status = jedis.smove("foo", "bar", "a");
|
||||
status = jedis.smove("foo", "bar", "a");
|
||||
|
||||
assertEquals(status, 0);
|
||||
assertEquals(status, 0);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
long bstatus = jedis.smove(bfoo, bbar, ba);
|
||||
long bstatus = jedis.smove(bfoo, bbar, ba);
|
||||
|
||||
Set<byte[]> bexpectedSrc = new HashSet<byte[]>();
|
||||
bexpectedSrc.add(bb);
|
||||
Set<byte[]> bexpectedSrc = new HashSet<byte[]>();
|
||||
bexpectedSrc.add(bb);
|
||||
|
||||
Set<byte[]> bexpectedDst = new HashSet<byte[]>();
|
||||
bexpectedDst.add(bc);
|
||||
bexpectedDst.add(ba);
|
||||
Set<byte[]> bexpectedDst = new HashSet<byte[]>();
|
||||
bexpectedDst.add(bc);
|
||||
bexpectedDst.add(ba);
|
||||
|
||||
assertEquals(bstatus, 1);
|
||||
assertEquals(bexpectedSrc, jedis.smembers(bfoo));
|
||||
assertEquals(bexpectedDst, jedis.smembers(bbar));
|
||||
assertEquals(bstatus, 1);
|
||||
assertEquals(bexpectedSrc, jedis.smembers(bfoo));
|
||||
assertEquals(bexpectedDst, jedis.smembers(bbar));
|
||||
|
||||
bstatus = jedis.smove(bfoo, bbar, ba);
|
||||
assertEquals(bstatus, 0);
|
||||
bstatus = jedis.smove(bfoo, bbar, ba);
|
||||
assertEquals(bstatus, 0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scard() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
long card = jedis.scard("foo");
|
||||
long card = jedis.scard("foo");
|
||||
|
||||
assertEquals(2, card);
|
||||
assertEquals(2, card);
|
||||
|
||||
card = jedis.scard("bar");
|
||||
assertEquals(0, card);
|
||||
card = jedis.scard("bar");
|
||||
assertEquals(0, card);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
long bcard = jedis.scard(bfoo);
|
||||
long bcard = jedis.scard(bfoo);
|
||||
|
||||
assertEquals(2, bcard);
|
||||
assertEquals(2, bcard);
|
||||
|
||||
bcard = jedis.scard(bbar);
|
||||
assertEquals(0, bcard);
|
||||
bcard = jedis.scard(bbar);
|
||||
assertEquals(0, bcard);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sismember() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
assertTrue(jedis.sismember("foo", "a"));
|
||||
assertTrue(jedis.sismember("foo", "a"));
|
||||
|
||||
assertFalse(jedis.sismember("foo", "c"));
|
||||
assertFalse(jedis.sismember("foo", "c"));
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
assertTrue(jedis.sismember(bfoo, ba));
|
||||
assertTrue(jedis.sismember(bfoo, ba));
|
||||
|
||||
assertFalse(jedis.sismember(bfoo, bc));
|
||||
assertFalse(jedis.sismember(bfoo, bc));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sinter() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("b");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("b");
|
||||
|
||||
Set<String> intersection = jedis.sinter("foo", "bar");
|
||||
assertEquals(expected, intersection);
|
||||
Set<String> intersection = jedis.sinter("foo", "bar");
|
||||
assertEquals(expected, intersection);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
|
||||
Set<byte[]> bintersection = jedis.sinter(bfoo, bbar);
|
||||
assertEquals(bexpected, bintersection);
|
||||
Set<byte[]> bintersection = jedis.sinter(bfoo, bbar);
|
||||
assertEquals(bexpected, bintersection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sinterstore() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("b");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("b");
|
||||
|
||||
long status = jedis.sinterstore("car", "foo", "bar");
|
||||
assertEquals(1, status);
|
||||
long status = jedis.sinterstore("car", "foo", "bar");
|
||||
assertEquals(1, status);
|
||||
|
||||
assertEquals(expected, jedis.smembers("car"));
|
||||
assertEquals(expected, jedis.smembers("car"));
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
|
||||
long bstatus = jedis.sinterstore(bcar, bfoo, bbar);
|
||||
assertEquals(1, bstatus);
|
||||
long bstatus = jedis.sinterstore(bcar, bfoo, bbar);
|
||||
assertEquals(1, bstatus);
|
||||
|
||||
assertEquals(bexpected, jedis.smembers(bcar));
|
||||
assertEquals(bexpected, jedis.smembers(bcar));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sunion() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
|
||||
Set<String> union = jedis.sunion("foo", "bar");
|
||||
assertEquals(expected, union);
|
||||
Set<String> union = jedis.sunion("foo", "bar");
|
||||
assertEquals(expected, union);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(bc);
|
||||
bexpected.add(ba);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(bc);
|
||||
bexpected.add(ba);
|
||||
|
||||
Set<byte[]> bunion = jedis.sunion(bfoo, bbar);
|
||||
assertEquals(bexpected, bunion);
|
||||
Set<byte[]> bunion = jedis.sunion(bfoo, bbar);
|
||||
assertEquals(bexpected, bunion);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sunionstore() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "b");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("a");
|
||||
expected.add("b");
|
||||
expected.add("c");
|
||||
|
||||
long status = jedis.sunionstore("car", "foo", "bar");
|
||||
assertEquals(3, status);
|
||||
long status = jedis.sunionstore("car", "foo", "bar");
|
||||
assertEquals(3, status);
|
||||
|
||||
assertEquals(expected, jedis.smembers("car"));
|
||||
assertEquals(expected, jedis.smembers("car"));
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bb);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(bc);
|
||||
bexpected.add(ba);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(bc);
|
||||
bexpected.add(ba);
|
||||
|
||||
long bstatus = jedis.sunionstore(bcar, bfoo, bbar);
|
||||
assertEquals(3, bstatus);
|
||||
long bstatus = jedis.sunionstore(bcar, bfoo, bbar);
|
||||
assertEquals(3, bstatus);
|
||||
|
||||
assertEquals(bexpected, jedis.smembers(bcar));
|
||||
assertEquals(bexpected, jedis.smembers(bcar));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sdiff() {
|
||||
jedis.sadd("foo", "x");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "c");
|
||||
jedis.sadd("foo", "x");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "c");
|
||||
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
jedis.sadd("car", "a");
|
||||
jedis.sadd("car", "d");
|
||||
jedis.sadd("car", "a");
|
||||
jedis.sadd("car", "d");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("x");
|
||||
expected.add("b");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("x");
|
||||
expected.add("b");
|
||||
|
||||
Set<String> diff = jedis.sdiff("foo", "bar", "car");
|
||||
assertEquals(expected, diff);
|
||||
Set<String> diff = jedis.sdiff("foo", "bar", "car");
|
||||
assertEquals(expected, diff);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, bx);
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
jedis.sadd(bfoo, bc);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, bx);
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
jedis.sadd(bfoo, bc);
|
||||
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
jedis.sadd(bcar, ba);
|
||||
jedis.sadd(bcar, bd);
|
||||
jedis.sadd(bcar, ba);
|
||||
jedis.sadd(bcar, bd);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(bx);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bb);
|
||||
bexpected.add(bx);
|
||||
|
||||
Set<byte[]> bdiff = jedis.sdiff(bfoo, bbar, bcar);
|
||||
assertEquals(bexpected, bdiff);
|
||||
Set<byte[]> bdiff = jedis.sdiff(bfoo, bbar, bcar);
|
||||
assertEquals(bexpected, bdiff);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sdiffstore() {
|
||||
jedis.sadd("foo", "x");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "c");
|
||||
jedis.sadd("foo", "x");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "c");
|
||||
|
||||
jedis.sadd("bar", "c");
|
||||
jedis.sadd("bar", "c");
|
||||
|
||||
jedis.sadd("car", "a");
|
||||
jedis.sadd("car", "d");
|
||||
jedis.sadd("car", "a");
|
||||
jedis.sadd("car", "d");
|
||||
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("d");
|
||||
expected.add("a");
|
||||
Set<String> expected = new HashSet<String>();
|
||||
expected.add("d");
|
||||
expected.add("a");
|
||||
|
||||
long status = jedis.sdiffstore("tar", "foo", "bar", "car");
|
||||
assertEquals(2, status);
|
||||
assertEquals(expected, jedis.smembers("car"));
|
||||
long status = jedis.sdiffstore("tar", "foo", "bar", "car");
|
||||
assertEquals(2, status);
|
||||
assertEquals(expected, jedis.smembers("car"));
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, bx);
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
jedis.sadd(bfoo, bc);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, bx);
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
jedis.sadd(bfoo, bc);
|
||||
|
||||
jedis.sadd(bbar, bc);
|
||||
jedis.sadd(bbar, bc);
|
||||
|
||||
jedis.sadd(bcar, ba);
|
||||
jedis.sadd(bcar, bd);
|
||||
jedis.sadd(bcar, ba);
|
||||
jedis.sadd(bcar, bd);
|
||||
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bd);
|
||||
bexpected.add(ba);
|
||||
Set<byte[]> bexpected = new HashSet<byte[]>();
|
||||
bexpected.add(bd);
|
||||
bexpected.add(ba);
|
||||
|
||||
long bstatus = jedis.sdiffstore("tar".getBytes(), bfoo, bbar, bcar);
|
||||
assertEquals(2, bstatus);
|
||||
assertEquals(bexpected, jedis.smembers(bcar));
|
||||
long bstatus = jedis.sdiffstore("tar".getBytes(), bfoo, bbar, bcar);
|
||||
assertEquals(2, bstatus);
|
||||
assertEquals(bexpected, jedis.smembers(bcar));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void srandmember() {
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
jedis.sadd("foo", "a");
|
||||
jedis.sadd("foo", "b");
|
||||
|
||||
String member = jedis.srandmember("foo");
|
||||
String member = jedis.srandmember("foo");
|
||||
|
||||
assertTrue("a".equals(member) || "b".equals(member));
|
||||
assertEquals(2, jedis.smembers("foo").size());
|
||||
assertTrue("a".equals(member) || "b".equals(member));
|
||||
assertEquals(2, jedis.smembers("foo").size());
|
||||
|
||||
member = jedis.srandmember("bar");
|
||||
assertNull(member);
|
||||
member = jedis.srandmember("bar");
|
||||
assertNull(member);
|
||||
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
// Binary
|
||||
jedis.sadd(bfoo, ba);
|
||||
jedis.sadd(bfoo, bb);
|
||||
|
||||
byte[] bmember = jedis.srandmember(bfoo);
|
||||
byte[] bmember = jedis.srandmember(bfoo);
|
||||
|
||||
assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
|
||||
assertEquals(2, jedis.smembers(bfoo).size());
|
||||
assertTrue(Arrays.equals(ba, bmember) || Arrays.equals(bb, bmember));
|
||||
assertEquals(2, jedis.smembers(bfoo).size());
|
||||
|
||||
bmember = jedis.srandmember(bbar);
|
||||
assertNull(bmember);
|
||||
bmember = jedis.srandmember(bbar);
|
||||
assertNull(bmember);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sscan() {
|
||||
jedis.sadd("foo", "a", "b");
|
||||
|
||||
|
||||
ScanResult<String> result = jedis.sscan("foo", 0);
|
||||
|
||||
assertEquals(0, result.getCursor());
|
||||
|
||||
@@ -7,42 +7,42 @@ import org.junit.Test;
|
||||
import redis.clients.util.Slowlog;
|
||||
|
||||
public class SlowlogCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
|
||||
@Test
|
||||
public void slowlog() {
|
||||
//do something
|
||||
// do something
|
||||
jedis.configSet("slowlog-log-slower-than", "0");
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo2", "bar2");
|
||||
|
||||
List<Slowlog> reducedLog = jedis.slowlogGet(1);
|
||||
assertEquals(1, reducedLog.size());
|
||||
|
||||
Slowlog log = reducedLog.get(0);
|
||||
assertTrue(log.getId() > 0);
|
||||
assertTrue(log.getTimeStamp() > 0);
|
||||
assertTrue(log.getExecutionTime() > 0);
|
||||
assertNotNull(log.getArgs());
|
||||
|
||||
List<byte[]> breducedLog = jedis.slowlogGetBinary(1);
|
||||
assertEquals(1, breducedLog.size());
|
||||
|
||||
List<Slowlog> log1 = jedis.slowlogGet();
|
||||
List<byte[]> blog1 = jedis.slowlogGetBinary();
|
||||
|
||||
assertNotNull(log1);
|
||||
assertNotNull(blog1);
|
||||
|
||||
long len1 = jedis.slowlogLen();
|
||||
|
||||
jedis.slowlogReset();
|
||||
|
||||
List<Slowlog> log2 = jedis.slowlogGet();
|
||||
List<byte[]> blog2 = jedis.slowlogGetBinary();
|
||||
long len2 = jedis.slowlogLen();
|
||||
|
||||
assertTrue(len1 > len2);
|
||||
assertTrue(log1.size() > log2.size());
|
||||
assertTrue(blog1.size() > blog2.size());
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo2", "bar2");
|
||||
|
||||
List<Slowlog> reducedLog = jedis.slowlogGet(1);
|
||||
assertEquals(1, reducedLog.size());
|
||||
|
||||
Slowlog log = reducedLog.get(0);
|
||||
assertTrue(log.getId() > 0);
|
||||
assertTrue(log.getTimeStamp() > 0);
|
||||
assertTrue(log.getExecutionTime() > 0);
|
||||
assertNotNull(log.getArgs());
|
||||
|
||||
List<byte[]> breducedLog = jedis.slowlogGetBinary(1);
|
||||
assertEquals(1, breducedLog.size());
|
||||
|
||||
List<Slowlog> log1 = jedis.slowlogGet();
|
||||
List<byte[]> blog1 = jedis.slowlogGetBinary();
|
||||
|
||||
assertNotNull(log1);
|
||||
assertNotNull(blog1);
|
||||
|
||||
long len1 = jedis.slowlogLen();
|
||||
|
||||
jedis.slowlogReset();
|
||||
|
||||
List<Slowlog> log2 = jedis.slowlogGet();
|
||||
List<byte[]> blog2 = jedis.slowlogGetBinary();
|
||||
long len2 = jedis.slowlogLen();
|
||||
|
||||
assertTrue(len1 > len2);
|
||||
assertTrue(log1.size() > log2.size());
|
||||
assertTrue(blog1.size() > blog2.size());
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,277 +25,277 @@ public class SortingCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
@Test
|
||||
public void sort() {
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "1");
|
||||
|
||||
List<String> result = jedis.sort("foo");
|
||||
List<String> result = jedis.sort("foo");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("3");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("3");
|
||||
|
||||
assertEquals(expected, result);
|
||||
assertEquals(expected, result);
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b3);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b1);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b3);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b1);
|
||||
|
||||
List<byte[]> bresult = jedis.sort(bfoo);
|
||||
List<byte[]> bresult = jedis.sort(bfoo);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b3);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b3);
|
||||
|
||||
assertEquals(bexpected, bresult);
|
||||
assertEquals(bexpected, bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortBy() {
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "1");
|
||||
|
||||
jedis.set("bar1", "3");
|
||||
jedis.set("bar2", "2");
|
||||
jedis.set("bar3", "1");
|
||||
jedis.set("bar1", "3");
|
||||
jedis.set("bar2", "2");
|
||||
jedis.set("bar3", "1");
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.by("bar*");
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.by("bar*");
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("2");
|
||||
expected.add("1");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("2");
|
||||
expected.add("1");
|
||||
|
||||
assertEquals(expected, result);
|
||||
assertEquals(expected, result);
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
jedis.lpush(bfoo, b1);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b3);
|
||||
jedis.lpush(bfoo, b1);
|
||||
|
||||
jedis.set(bbar1, b3);
|
||||
jedis.set(bbar2, b2);
|
||||
jedis.set(bbar3, b1);
|
||||
jedis.set(bbar1, b3);
|
||||
jedis.set(bbar2, b2);
|
||||
jedis.set(bbar3, b1);
|
||||
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.by(bbarstar);
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.by(bbarstar);
|
||||
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b1);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b1);
|
||||
|
||||
assertEquals(bexpected, bresult);
|
||||
assertEquals(bexpected, bresult);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortDesc() {
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "3");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "1");
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.desc();
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.desc();
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("2");
|
||||
expected.add("1");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("3");
|
||||
expected.add("2");
|
||||
expected.add("1");
|
||||
|
||||
assertEquals(expected, result);
|
||||
assertEquals(expected, result);
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b3);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b1);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b3);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b1);
|
||||
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.desc();
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.desc();
|
||||
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b1);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b3);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b1);
|
||||
|
||||
assertEquals(bexpected, bresult);
|
||||
assertEquals(bexpected, bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortLimit() {
|
||||
for (int n = 10; n > 0; n--) {
|
||||
jedis.lpush("foo", String.valueOf(n));
|
||||
}
|
||||
for (int n = 10; n > 0; n--) {
|
||||
jedis.lpush("foo", String.valueOf(n));
|
||||
}
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.limit(0, 3);
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.limit(0, 3);
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("3");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("3");
|
||||
|
||||
assertEquals(expected, result);
|
||||
assertEquals(expected, result);
|
||||
|
||||
// Binary
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '4' });
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '3' });
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '2' });
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '1' });
|
||||
// Binary
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '4' });
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '3' });
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '2' });
|
||||
jedis.rpush(bfoo, new byte[] { (byte) '1' });
|
||||
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.limit(0, 3);
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.limit(0, 3);
|
||||
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b3);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b3);
|
||||
|
||||
assertEquals(bexpected, bresult);
|
||||
assertEquals(bexpected, bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortAlpha() {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.alpha();
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.alpha();
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("10");
|
||||
expected.add("2");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("10");
|
||||
expected.add("2");
|
||||
|
||||
assertEquals(expected, result);
|
||||
assertEquals(expected, result);
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b10);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b10);
|
||||
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.alpha();
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.alpha();
|
||||
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b10);
|
||||
bexpected.add(b2);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b10);
|
||||
bexpected.add(b2);
|
||||
|
||||
assertEquals(bexpected, bresult);
|
||||
assertEquals(bexpected, bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortGet() {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
|
||||
jedis.set("bar1", "bar1");
|
||||
jedis.set("bar2", "bar2");
|
||||
jedis.set("bar10", "bar10");
|
||||
jedis.set("bar1", "bar1");
|
||||
jedis.set("bar2", "bar2");
|
||||
jedis.set("bar10", "bar10");
|
||||
|
||||
jedis.set("car1", "car1");
|
||||
jedis.set("car2", "car2");
|
||||
jedis.set("car10", "car10");
|
||||
jedis.set("car1", "car1");
|
||||
jedis.set("car2", "car2");
|
||||
jedis.set("car10", "car10");
|
||||
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.get("car*", "bar*");
|
||||
SortingParams sp = new SortingParams();
|
||||
sp.get("car*", "bar*");
|
||||
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
List<String> result = jedis.sort("foo", sp);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("car1");
|
||||
expected.add("bar1");
|
||||
expected.add("car2");
|
||||
expected.add("bar2");
|
||||
expected.add("car10");
|
||||
expected.add("bar10");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("car1");
|
||||
expected.add("bar1");
|
||||
expected.add("car2");
|
||||
expected.add("bar2");
|
||||
expected.add("car10");
|
||||
expected.add("bar10");
|
||||
|
||||
assertEquals(expected, result);
|
||||
assertEquals(expected, result);
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b10);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b10);
|
||||
|
||||
jedis.set(bbar1, bbar1);
|
||||
jedis.set(bbar2, bbar2);
|
||||
jedis.set(bbar10, bbar10);
|
||||
jedis.set(bbar1, bbar1);
|
||||
jedis.set(bbar2, bbar2);
|
||||
jedis.set(bbar10, bbar10);
|
||||
|
||||
jedis.set(bcar1, bcar1);
|
||||
jedis.set(bcar2, bcar2);
|
||||
jedis.set(bcar10, bcar10);
|
||||
jedis.set(bcar1, bcar1);
|
||||
jedis.set(bcar2, bcar2);
|
||||
jedis.set(bcar10, bcar10);
|
||||
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.get(bcarstar, bbarstar);
|
||||
SortingParams bsp = new SortingParams();
|
||||
bsp.get(bcarstar, bbarstar);
|
||||
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
List<byte[]> bresult = jedis.sort(bfoo, bsp);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bcar1);
|
||||
bexpected.add(bbar1);
|
||||
bexpected.add(bcar2);
|
||||
bexpected.add(bbar2);
|
||||
bexpected.add(bcar10);
|
||||
bexpected.add(bbar10);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bcar1);
|
||||
bexpected.add(bbar1);
|
||||
bexpected.add(bcar2);
|
||||
bexpected.add(bbar2);
|
||||
bexpected.add(bcar10);
|
||||
bexpected.add(bbar10);
|
||||
|
||||
assertEquals(bexpected, bresult);
|
||||
assertEquals(bexpected, bresult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sortStore() {
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
jedis.lpush("foo", "1");
|
||||
jedis.lpush("foo", "2");
|
||||
jedis.lpush("foo", "10");
|
||||
|
||||
long result = jedis.sort("foo", "result");
|
||||
long result = jedis.sort("foo", "result");
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("10");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1");
|
||||
expected.add("2");
|
||||
expected.add("10");
|
||||
|
||||
assertEquals(3, result);
|
||||
assertEquals(expected, jedis.lrange("result", 0, 1000));
|
||||
assertEquals(3, result);
|
||||
assertEquals(expected, jedis.lrange("result", 0, 1000));
|
||||
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b10);
|
||||
// Binary
|
||||
jedis.lpush(bfoo, b1);
|
||||
jedis.lpush(bfoo, b2);
|
||||
jedis.lpush(bfoo, b10);
|
||||
|
||||
byte[] bkresult = new byte[] { 0X09, 0x0A, 0x0B, 0x0C };
|
||||
long bresult = jedis.sort(bfoo, bkresult);
|
||||
byte[] bkresult = new byte[] { 0X09, 0x0A, 0x0B, 0x0C };
|
||||
long bresult = jedis.sort(bfoo, bkresult);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b10);
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(b1);
|
||||
bexpected.add(b2);
|
||||
bexpected.add(b10);
|
||||
|
||||
assertEquals(3, bresult);
|
||||
assertEquals(bexpected, jedis.lrange(bkresult, 0, 1000));
|
||||
assertEquals(3, bresult);
|
||||
assertEquals(bexpected, jedis.lrange(bkresult, 0, 1000));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,200 +10,200 @@ import redis.clients.jedis.exceptions.JedisDataException;
|
||||
public class StringValuesCommandsTest extends JedisCommandTestBase {
|
||||
@Test
|
||||
public void setAndGet() {
|
||||
String status = jedis.set("foo", "bar");
|
||||
assertEquals("OK", status);
|
||||
String status = jedis.set("foo", "bar");
|
||||
assertEquals("OK", status);
|
||||
|
||||
String value = jedis.get("foo");
|
||||
assertEquals("bar", value);
|
||||
String value = jedis.get("foo");
|
||||
assertEquals("bar", value);
|
||||
|
||||
assertEquals(null, jedis.get("bar"));
|
||||
assertEquals(null, jedis.get("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSet() {
|
||||
String value = jedis.getSet("foo", "bar");
|
||||
assertEquals(null, value);
|
||||
value = jedis.get("foo");
|
||||
assertEquals("bar", value);
|
||||
String value = jedis.getSet("foo", "bar");
|
||||
assertEquals(null, value);
|
||||
value = jedis.get("foo");
|
||||
assertEquals("bar", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mget() {
|
||||
List<String> values = jedis.mget("foo", "bar");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add(null);
|
||||
expected.add(null);
|
||||
List<String> values = jedis.mget("foo", "bar");
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add(null);
|
||||
expected.add(null);
|
||||
|
||||
assertEquals(expected, values);
|
||||
assertEquals(expected, values);
|
||||
|
||||
jedis.set("foo", "bar");
|
||||
jedis.set("foo", "bar");
|
||||
|
||||
expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add(null);
|
||||
values = jedis.mget("foo", "bar");
|
||||
expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add(null);
|
||||
values = jedis.mget("foo", "bar");
|
||||
|
||||
assertEquals(expected, values);
|
||||
assertEquals(expected, values);
|
||||
|
||||
jedis.set("bar", "foo");
|
||||
jedis.set("bar", "foo");
|
||||
|
||||
expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add("foo");
|
||||
values = jedis.mget("foo", "bar");
|
||||
expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add("foo");
|
||||
values = jedis.mget("foo", "bar");
|
||||
|
||||
assertEquals(expected, values);
|
||||
assertEquals(expected, values);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setnx() {
|
||||
long status = jedis.setnx("foo", "bar");
|
||||
assertEquals(1, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
long status = jedis.setnx("foo", "bar");
|
||||
assertEquals(1, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
|
||||
status = jedis.setnx("foo", "bar2");
|
||||
assertEquals(0, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
status = jedis.setnx("foo", "bar2");
|
||||
assertEquals(0, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setex() {
|
||||
String status = jedis.setex("foo", 20, "bar");
|
||||
assertEquals("OK", status);
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertTrue(ttl > 0 && ttl <= 20);
|
||||
String status = jedis.setex("foo", 20, "bar");
|
||||
assertEquals("OK", status);
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertTrue(ttl > 0 && ttl <= 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mset() {
|
||||
String status = jedis.mset("foo", "bar", "bar", "foo");
|
||||
assertEquals("OK", status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
assertEquals("foo", jedis.get("bar"));
|
||||
String status = jedis.mset("foo", "bar", "bar", "foo");
|
||||
assertEquals("OK", status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
assertEquals("foo", jedis.get("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void msetnx() {
|
||||
long status = jedis.msetnx("foo", "bar", "bar", "foo");
|
||||
assertEquals(1, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
assertEquals("foo", jedis.get("bar"));
|
||||
long status = jedis.msetnx("foo", "bar", "bar", "foo");
|
||||
assertEquals(1, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
assertEquals("foo", jedis.get("bar"));
|
||||
|
||||
status = jedis.msetnx("foo", "bar1", "bar2", "foo2");
|
||||
assertEquals(0, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
assertEquals("foo", jedis.get("bar"));
|
||||
status = jedis.msetnx("foo", "bar1", "bar2", "foo2");
|
||||
assertEquals(0, status);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
assertEquals("foo", jedis.get("bar"));
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void incrWrongValue() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.incr("foo");
|
||||
jedis.set("foo", "bar");
|
||||
jedis.incr("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incr() {
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(1, value);
|
||||
value = jedis.incr("foo");
|
||||
assertEquals(2, value);
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(1, value);
|
||||
value = jedis.incr("foo");
|
||||
assertEquals(2, value);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void incrByWrongValue() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.incrBy("foo", 2);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.incrBy("foo", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incrBy() {
|
||||
long value = jedis.incrBy("foo", 2);
|
||||
assertEquals(2, value);
|
||||
value = jedis.incrBy("foo", 2);
|
||||
assertEquals(4, value);
|
||||
long value = jedis.incrBy("foo", 2);
|
||||
assertEquals(2, value);
|
||||
value = jedis.incrBy("foo", 2);
|
||||
assertEquals(4, value);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void decrWrongValue() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.decr("foo");
|
||||
jedis.set("foo", "bar");
|
||||
jedis.decr("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decr() {
|
||||
long value = jedis.decr("foo");
|
||||
assertEquals(-1, value);
|
||||
value = jedis.decr("foo");
|
||||
assertEquals(-2, value);
|
||||
long value = jedis.decr("foo");
|
||||
assertEquals(-1, value);
|
||||
value = jedis.decr("foo");
|
||||
assertEquals(-2, value);
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void decrByWrongValue() {
|
||||
jedis.set("foo", "bar");
|
||||
jedis.decrBy("foo", 2);
|
||||
jedis.set("foo", "bar");
|
||||
jedis.decrBy("foo", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decrBy() {
|
||||
long value = jedis.decrBy("foo", 2);
|
||||
assertEquals(-2, value);
|
||||
value = jedis.decrBy("foo", 2);
|
||||
assertEquals(-4, value);
|
||||
long value = jedis.decrBy("foo", 2);
|
||||
assertEquals(-2, value);
|
||||
value = jedis.decrBy("foo", 2);
|
||||
assertEquals(-4, value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append() {
|
||||
long value = jedis.append("foo", "bar");
|
||||
assertEquals(3, value);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
value = jedis.append("foo", "bar");
|
||||
assertEquals(6, value);
|
||||
assertEquals("barbar", jedis.get("foo"));
|
||||
long value = jedis.append("foo", "bar");
|
||||
assertEquals(3, value);
|
||||
assertEquals("bar", jedis.get("foo"));
|
||||
value = jedis.append("foo", "bar");
|
||||
assertEquals(6, value);
|
||||
assertEquals("barbar", jedis.get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substr() {
|
||||
jedis.set("s", "This is a string");
|
||||
assertEquals("This", jedis.substr("s", 0, 3));
|
||||
assertEquals("ing", jedis.substr("s", -3, -1));
|
||||
assertEquals("This is a string", jedis.substr("s", 0, -1));
|
||||
assertEquals(" string", jedis.substr("s", 9, 100000));
|
||||
jedis.set("s", "This is a string");
|
||||
assertEquals("This", jedis.substr("s", 0, 3));
|
||||
assertEquals("ing", jedis.substr("s", -3, -1));
|
||||
assertEquals("This is a string", jedis.substr("s", 0, -1));
|
||||
assertEquals(" string", jedis.substr("s", 9, 100000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strlen() {
|
||||
jedis.set("s", "This is a string");
|
||||
assertEquals("This is a string".length(), jedis.strlen("s").intValue());
|
||||
jedis.set("s", "This is a string");
|
||||
assertEquals("This is a string".length(), jedis.strlen("s").intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incrLargeNumbers() {
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(1, value);
|
||||
assertEquals(1L + Integer.MAX_VALUE, (long) jedis.incrBy("foo",
|
||||
Integer.MAX_VALUE));
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(1, value);
|
||||
assertEquals(1L + Integer.MAX_VALUE,
|
||||
(long) jedis.incrBy("foo", Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test(expected = JedisDataException.class)
|
||||
public void incrReallyLargeNumbers() {
|
||||
jedis.set("foo", Long.toString(Long.MAX_VALUE));
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(Long.MIN_VALUE, value);
|
||||
jedis.set("foo", Long.toString(Long.MAX_VALUE));
|
||||
long value = jedis.incr("foo");
|
||||
assertEquals(Long.MIN_VALUE, value);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void incrByFloat() {
|
||||
double value = jedis.incrByFloat("foo", 10.5);
|
||||
assertEquals(10.5, value, 0.0);
|
||||
value = jedis.incrByFloat("foo", 0.1);
|
||||
assertEquals(10.6, value, 0.0);
|
||||
double value = jedis.incrByFloat("foo", 10.5);
|
||||
assertEquals(10.5, value, 0.0);
|
||||
value = jedis.incrByFloat("foo", 0.1);
|
||||
assertEquals(10.6, value, 0.0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void psetex() {
|
||||
String status = jedis.psetex("foo", 20000, "bar");
|
||||
assertEquals("OK", status);
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertTrue(ttl > 0 && ttl <= 20000);
|
||||
String status = jedis.psetex("foo", 20000, "bar");
|
||||
assertEquals("OK", status);
|
||||
long ttl = jedis.ttl("foo");
|
||||
assertTrue(ttl > 0 && ttl <= 20000);
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,12 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
import redis.clients.jedis.Protocol.Keyword;
|
||||
import redis.clients.jedis.Response;
|
||||
import redis.clients.jedis.Transaction;
|
||||
import redis.clients.jedis.TransactionBlock;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
@@ -296,48 +295,48 @@ public class TransactionCommandsTest extends JedisCommandTestBase {
|
||||
|
||||
assertNull(results);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResetStateWhenInMulti() {
|
||||
jedis.auth("foobared");
|
||||
|
||||
Transaction t = jedis.multi();
|
||||
t.set("foooo", "barrr");
|
||||
|
||||
jedis.resetState();
|
||||
assertEquals(null, jedis.get("foooo"));
|
||||
jedis.auth("foobared");
|
||||
|
||||
Transaction t = jedis.multi();
|
||||
t.set("foooo", "barrr");
|
||||
|
||||
jedis.resetState();
|
||||
assertEquals(null, jedis.get("foooo"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testResetStateWhenInMultiWithinPipeline() {
|
||||
jedis.auth("foobared");
|
||||
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.multi();
|
||||
p.set("foooo", "barrr");
|
||||
jedis.auth("foobared");
|
||||
|
||||
jedis.resetState();
|
||||
assertEquals(null, jedis.get("foooo"));
|
||||
Pipeline p = jedis.pipelined();
|
||||
p.multi();
|
||||
p.set("foooo", "barrr");
|
||||
|
||||
jedis.resetState();
|
||||
assertEquals(null, jedis.get("foooo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetStateWhenInWatch() {
|
||||
jedis.watch("mykey", "somekey");
|
||||
|
||||
// state reset : unwatch
|
||||
jedis.resetState();
|
||||
|
||||
Transaction t = jedis.multi();
|
||||
jedis.watch("mykey", "somekey");
|
||||
|
||||
nj.connect();
|
||||
nj.auth("foobared");
|
||||
nj.set("mykey", "bar");
|
||||
nj.disconnect();
|
||||
// state reset : unwatch
|
||||
jedis.resetState();
|
||||
|
||||
t.set("mykey", "foo");
|
||||
List<Object> resp = t.exec();
|
||||
assertNotNull(resp);
|
||||
assertEquals(1, resp.size());
|
||||
assertEquals("foo", jedis.get("mykey"));
|
||||
Transaction t = jedis.multi();
|
||||
|
||||
nj.connect();
|
||||
nj.auth("foobared");
|
||||
nj.set("mykey", "bar");
|
||||
nj.disconnect();
|
||||
|
||||
t.set("mykey", "foo");
|
||||
List<Object> resp = t.exec();
|
||||
assertNotNull(resp);
|
||||
assertEquals(1, resp.size());
|
||||
assertEquals("foo", jedis.get("mykey"));
|
||||
}
|
||||
}
|
||||
@@ -10,181 +10,181 @@ import java.util.Set;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VariadicCommandsTest extends JedisCommandTestBase {
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
final byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };
|
||||
final byte[] bbar = { 0x05, 0x06, 0x07, 0x08 };
|
||||
final byte[] bcar = { 0x09, 0x0A, 0x0B, 0x0C };
|
||||
final byte[] bfoo1 = { 0x01, 0x02, 0x03, 0x04, 0x0A };
|
||||
final byte[] bfoo2 = { 0x01, 0x02, 0x03, 0x04, 0x0B };
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void hdel() {
|
||||
Map<String, String> hash = new HashMap<String, String>();
|
||||
hash.put("bar", "car");
|
||||
hash.put("car", "bar");
|
||||
hash.put("foo2", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
Map<String, String> hash = new HashMap<String, String>();
|
||||
hash.put("bar", "car");
|
||||
hash.put("car", "bar");
|
||||
hash.put("foo2", "bar");
|
||||
jedis.hmset("foo", hash);
|
||||
|
||||
assertEquals(0, jedis.hdel("bar", "foo", "foo1").intValue());
|
||||
assertEquals(0, jedis.hdel("foo", "foo", "foo1").intValue());
|
||||
assertEquals(2, jedis.hdel("foo", "bar", "foo2").intValue());
|
||||
assertEquals(null, jedis.hget("foo", "bar"));
|
||||
assertEquals(0, jedis.hdel("bar", "foo", "foo1").intValue());
|
||||
assertEquals(0, jedis.hdel("foo", "foo", "foo1").intValue());
|
||||
assertEquals(2, jedis.hdel("foo", "bar", "foo2").intValue());
|
||||
assertEquals(null, jedis.hget("foo", "bar"));
|
||||
|
||||
// Binary
|
||||
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||
bhash.put(bbar, bcar);
|
||||
bhash.put(bcar, bbar);
|
||||
bhash.put(bfoo2, bbar);
|
||||
jedis.hmset(bfoo, bhash);
|
||||
// Binary
|
||||
Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>();
|
||||
bhash.put(bbar, bcar);
|
||||
bhash.put(bcar, bbar);
|
||||
bhash.put(bfoo2, bbar);
|
||||
jedis.hmset(bfoo, bhash);
|
||||
|
||||
assertEquals(0, jedis.hdel(bbar, bfoo, bfoo1).intValue());
|
||||
assertEquals(0, jedis.hdel(bfoo, bfoo, bfoo1).intValue());
|
||||
assertEquals(2, jedis.hdel(bfoo, bbar, bfoo2).intValue());
|
||||
assertEquals(null, jedis.hget(bfoo, bbar));
|
||||
assertEquals(0, jedis.hdel(bbar, bfoo, bfoo1).intValue());
|
||||
assertEquals(0, jedis.hdel(bfoo, bfoo, bfoo1).intValue());
|
||||
assertEquals(2, jedis.hdel(bfoo, bbar, bfoo2).intValue());
|
||||
assertEquals(null, jedis.hget(bfoo, bbar));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void rpush() {
|
||||
long size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(2, size);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add("foo");
|
||||
|
||||
List<String> values = jedis.lrange("foo",0,-1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
size = jedis.rpush(bfoo, bbar, bfoo);
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bbar);
|
||||
bexpected.add(bfoo);
|
||||
long size = jedis.rpush("foo", "bar", "foo");
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
|
||||
assertEquals(bexpected, bvalues);
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("bar");
|
||||
expected.add("foo");
|
||||
|
||||
List<String> values = jedis.lrange("foo", 0, -1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
size = jedis.rpush(bfoo, bbar, bfoo);
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bbar);
|
||||
bexpected.add(bfoo);
|
||||
|
||||
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
|
||||
assertEquals(bexpected, bvalues);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void lpush() {
|
||||
long size = jedis.lpush("foo", "bar", "foo");
|
||||
assertEquals(2, size);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("foo");
|
||||
expected.add("bar");
|
||||
|
||||
List<String> values = jedis.lrange("foo",0,-1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
size = jedis.lpush(bfoo, bbar, bfoo);
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bfoo);
|
||||
bexpected.add(bbar);
|
||||
long size = jedis.lpush("foo", "bar", "foo");
|
||||
assertEquals(2, size);
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("foo");
|
||||
expected.add("bar");
|
||||
|
||||
List<String> values = jedis.lrange("foo", 0, -1);
|
||||
assertEquals(expected, values);
|
||||
|
||||
// Binary
|
||||
size = jedis.lpush(bfoo, bbar, bfoo);
|
||||
assertEquals(2, size);
|
||||
|
||||
List<byte[]> bexpected = new ArrayList<byte[]>();
|
||||
bexpected.add(bfoo);
|
||||
bexpected.add(bbar);
|
||||
|
||||
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
|
||||
assertEquals(bexpected, bvalues);
|
||||
|
||||
List<byte[]> bvalues = jedis.lrange(bfoo, 0, -1);
|
||||
assertEquals(bexpected, bvalues);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void sadd() {
|
||||
long status = jedis.sadd("foo", "bar", "foo1");
|
||||
assertEquals(2, status);
|
||||
long status = jedis.sadd("foo", "bar", "foo1");
|
||||
assertEquals(2, status);
|
||||
|
||||
status = jedis.sadd("foo", "bar", "car");
|
||||
assertEquals(1, status);
|
||||
status = jedis.sadd("foo", "bar", "car");
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.sadd("foo", "bar", "foo1");
|
||||
assertEquals(0, status);
|
||||
status = jedis.sadd("foo", "bar", "foo1");
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.sadd(bfoo, bbar, bfoo1);
|
||||
assertEquals(2, status);
|
||||
status = jedis.sadd(bfoo, bbar, bfoo1);
|
||||
assertEquals(2, status);
|
||||
|
||||
status = jedis.sadd(bfoo, bbar, bcar);
|
||||
assertEquals(1, status);
|
||||
status = jedis.sadd(bfoo, bbar, bcar);
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.sadd(bfoo, bbar, bfoo1);
|
||||
assertEquals(0, status);
|
||||
status = jedis.sadd(bfoo, bbar, bfoo1);
|
||||
assertEquals(0, status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void zadd() {
|
||||
Map<String, Double> scoreMembers = new HashMap<String, Double>();
|
||||
scoreMembers.put("bar", 1d);
|
||||
scoreMembers.put("foo", 10d);
|
||||
|
||||
long status = jedis.zadd("foo", scoreMembers);
|
||||
assertEquals(2, status);
|
||||
Map<String, Double> scoreMembers = new HashMap<String, Double>();
|
||||
scoreMembers.put("bar", 1d);
|
||||
scoreMembers.put("foo", 10d);
|
||||
|
||||
scoreMembers.clear();
|
||||
scoreMembers.put("car", 0.1d);
|
||||
scoreMembers.put("bar", 2d);
|
||||
|
||||
status = jedis.zadd("foo", scoreMembers);
|
||||
assertEquals(1, status);
|
||||
long status = jedis.zadd("foo", scoreMembers);
|
||||
assertEquals(2, status);
|
||||
|
||||
Map<byte[], Double> bscoreMembers = new HashMap<byte[], Double>();
|
||||
bscoreMembers.put(bbar, 1d);
|
||||
bscoreMembers.put(bfoo, 10d);
|
||||
|
||||
status = jedis.zadd(bfoo, bscoreMembers);
|
||||
assertEquals(2, status);
|
||||
scoreMembers.clear();
|
||||
scoreMembers.put("car", 0.1d);
|
||||
scoreMembers.put("bar", 2d);
|
||||
|
||||
bscoreMembers.clear();
|
||||
bscoreMembers.put(bcar, 0.1d);
|
||||
bscoreMembers.put(bbar, 2d);
|
||||
|
||||
status = jedis.zadd(bfoo, bscoreMembers);
|
||||
assertEquals(1, status);
|
||||
status = jedis.zadd("foo", scoreMembers);
|
||||
assertEquals(1, status);
|
||||
|
||||
Map<byte[], Double> bscoreMembers = new HashMap<byte[], Double>();
|
||||
bscoreMembers.put(bbar, 1d);
|
||||
bscoreMembers.put(bfoo, 10d);
|
||||
|
||||
status = jedis.zadd(bfoo, bscoreMembers);
|
||||
assertEquals(2, status);
|
||||
|
||||
bscoreMembers.clear();
|
||||
bscoreMembers.put(bcar, 0.1d);
|
||||
bscoreMembers.put(bbar, 2d);
|
||||
|
||||
status = jedis.zadd(bfoo, bscoreMembers);
|
||||
assertEquals(1, status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zrem() {
|
||||
jedis.zadd("foo", 1d, "bar");
|
||||
jedis.zadd("foo", 2d, "car");
|
||||
jedis.zadd("foo", 3d, "foo1");
|
||||
jedis.zadd("foo", 1d, "bar");
|
||||
jedis.zadd("foo", 2d, "car");
|
||||
jedis.zadd("foo", 3d, "foo1");
|
||||
|
||||
long status = jedis.zrem("foo", "bar", "car");
|
||||
long status = jedis.zrem("foo", "bar", "car");
|
||||
|
||||
Set<String> expected = new LinkedHashSet<String>();
|
||||
expected.add("foo1");
|
||||
Set<String> expected = new LinkedHashSet<String>();
|
||||
expected.add("foo1");
|
||||
|
||||
assertEquals(2, status);
|
||||
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
||||
assertEquals(2, status);
|
||||
assertEquals(expected, jedis.zrange("foo", 0, 100));
|
||||
|
||||
status = jedis.zrem("foo", "bar", "car");
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.zrem("foo", "bar", "foo1");
|
||||
assertEquals(1, status);
|
||||
status = jedis.zrem("foo", "bar", "car");
|
||||
assertEquals(0, status);
|
||||
|
||||
//Binary
|
||||
jedis.zadd(bfoo, 1d, bbar);
|
||||
jedis.zadd(bfoo, 2d, bcar);
|
||||
jedis.zadd(bfoo, 3d, bfoo1);
|
||||
status = jedis.zrem("foo", "bar", "foo1");
|
||||
assertEquals(1, status);
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bcar);
|
||||
// Binary
|
||||
jedis.zadd(bfoo, 1d, bbar);
|
||||
jedis.zadd(bfoo, 2d, bcar);
|
||||
jedis.zadd(bfoo, 3d, bfoo1);
|
||||
|
||||
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bfoo);
|
||||
status = jedis.zrem(bfoo, bbar, bcar);
|
||||
|
||||
assertEquals(2, status);
|
||||
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||
Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
|
||||
bexpected.add(bfoo);
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bcar);
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bfoo1);
|
||||
assertEquals(1, status);
|
||||
assertEquals(2, status);
|
||||
assertEquals(bexpected, jedis.zrange(bfoo, 0, 100));
|
||||
|
||||
}
|
||||
status = jedis.zrem(bfoo, bbar, bcar);
|
||||
assertEquals(0, status);
|
||||
|
||||
status = jedis.zrem(bfoo, bbar, bfoo1);
|
||||
assertEquals(1, status);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user