@Test
 public void del() {
   rc.del(a("key1", "key2", "key3"));
   eq("OK", rc.set("key1", "Hello"));
   eq("OK", rc.set("key2", "World"));
   eq(2, rc.del(a("key1", "key2", "key3")));
 }
 @Test
 public void append() {
   rc.del(a("mykey"));
   eq(5, rc.append("mykey", "Hello"));
   eq(11, rc.append("mykey", " World"));
   eq("Hello World", rc.get("mykey"));
 }
 @Test
 public void zcard() {
   rc.del(a("myzset"));
   eq(1, rc.zadd(a("myzset", "1", "one")));
   eq(1, rc.zadd(a("myzset", "2", "two")));
   eq(2, rc.zcard("myzset"));
 }
 @Test
 public void exists() {
   rc.del_("key1", "key2");
   eq("OK", rc.set("key1", "value"));
   eq(1, rc.exists("key1"));
   eq(0, rc.exists("key2"));
 }
 @Test
 public void zincrby() {
   rc.del(a("myzset"));
   eq(1, rc.zadd(a("myzset", "1", "one")));
   eq(1, rc.zadd(a("myzset", "2", "two")));
   eq("3", rc.zincrby("myzset", "2", "one"));
   eq(a("two", "2", "one", "3"), rc.zrange("myzset", "0", "-1", WITHSCORES));
 }
 @Test
 public void zrevrank() {
   rc.del(a("myzset"));
   eq(1, rc.zadd(a("myzset", "1", "one")));
   eq(1, rc.zadd(a("myzset", "2", "two")));
   eq(1, rc.zadd(a("myzset", "3", "three")));
   eq(2, (IntegerReply) rc.zrevrank("myzset", "one"));
   eq(null, (BulkReply) rc.zrevrank("myzset", "four"));
 }
 @Test
 public void zremrangebyscore() {
   rc.del(a("myzset"));
   eq(1, rc.zadd(a("myzset", "1", "one")));
   eq(1, rc.zadd(a("myzset", "2", "two")));
   eq(1, rc.zadd(a("myzset", "3", "three")));
   eq(1, rc.zremrangebyscore("myzset", "-inf", "(2"));
   eq(a("two", "2", "three", "3"), rc.zrange("myzset", "0", "-1", WITHSCORES));
 }
 @Test
 public void zrem() {
   rc.del(a("myzset"));
   eq(1, rc.zadd(a("myzset", "1", "one")));
   eq(1, rc.zadd(a("myzset", "2", "two")));
   eq(1, rc.zadd(a("myzset", "3", "three")));
   eq(1, rc.zrem_("myzset", "two"));
   eq(a("one", "1", "three", "3"), rc.zrange("myzset", "0", "-1", WITHSCORES));
 }
 @Test
 public void zcount() {
   rc.del(a("myzset"));
   eq(1, rc.zadd(a("myzset", "1", "one")));
   eq(1, rc.zadd(a("myzset", "2", "two")));
   eq(1, rc.zadd(a("myzset", "3", "three")));
   eq(3, rc.zcount("myzset", "-inf", "inf"));
   eq(2, rc.zcount("myzset", "(1", "3"));
 }
示例#10
0
 @Test
 public void decr() {
   eq("OK", rc.set("mykey", "10"));
   eq(9, rc.decr("mykey"));
   eq("OK", rc.set("mykey", "234293482390480948029348230948"));
   try {
     rc.decr("mykey");
     fail("Should have failed");
   } catch (RedisException e) {
     // failed
   }
 }
 public Object execute(String command, byte[]... args) {
   Assert.hasText(command, "a valid command needs to be specified");
   try {
     String name = command.trim().toUpperCase();
     Command cmd = new Command(name.getBytes(Charsets.UTF_8), args);
     if (isPipelined()) {
       pipeline(client.pipeline(name, cmd));
       return null;
     } else {
       return client.execute(name, cmd);
     }
   } catch (RedisException ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void select(int dbIndex) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.select(dbIndex));
     }
     client.select(dbIndex);
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Long rPush(byte[] key, byte[] value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.rpush(key, new Object[] {value}));
       return null;
     }
     return client.rpush(key, new Object[] {value}).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void setRange(byte[] key, byte[] value, long start) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.setrange(key, start, value));
       return;
     }
     client.setrange(key, start, value);
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Long strLen(byte[] key) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.strlen(key));
       return null;
     }
     return client.strlen(key).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Boolean getBit(byte[] key, long offset) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.getbit(key, offset));
       return null;
     }
     return (client.getbit(key, offset).data() == 1);
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void setBit(byte[] key, long offset, boolean value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.setbit(key, offset, SrpUtils.asBit(value)));
       return;
     }
     client.setbit(key, offset, SrpUtils.asBit(value));
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Long incrBy(byte[] key, long value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.incrby(key, value));
       return null;
     }
     return client.incrby(key, value).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public byte[] lIndex(byte[] key, long index) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.lindex(key, index));
       return null;
     }
     return client.lindex(key, index).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public byte[] rPop(byte[] key) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.rpop(key));
       return null;
     }
     return client.rpop(key).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void lSet(byte[] key, long index, byte[] value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.lset(key, index, value));
       return;
     }
     client.lset(key, index, value);
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public List<byte[]> lRange(byte[] key, long start, long end) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.lrange(key, start, end));
       return null;
     }
     return SrpUtils.toBytesList(client.lrange(key, start, end).data());
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Long lInsert(byte[] key, Position where, byte[] pivot, byte[] value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.linsert(key, SrpUtils.convertPosition(where), pivot, value));
       return null;
     }
     return client.linsert(key, SrpUtils.convertPosition(where), pivot, value).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void mSetNX(Map<byte[], byte[]> tuples) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.msetnx((Object[]) SrpUtils.convert(tuples)));
       return;
     }
     client.msetnx((Object[]) SrpUtils.convert(tuples));
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Long lRem(byte[] key, long count, byte[] value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.lrem(key, count, value));
       return null;
     }
     return client.lrem(key, count, value).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void setEx(byte[] key, long time, byte[] value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.setex(key, time, value));
       return;
     }
     client.setex(key, time, value);
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public void lTrim(byte[] key, long start, long end) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.ltrim(key, start, end));
       return;
     }
     client.ltrim(key, start, end);
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public Boolean setNX(byte[] key, byte[] value) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.setnx(key, value));
       return null;
     }
     return client.setnx(key, value).data() == 1;
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public byte[] rPopLPush(byte[] srcKey, byte[] dstKey) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.rpoplpush(srcKey, dstKey));
       return null;
     }
     return client.rpoplpush(srcKey, dstKey).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }
 public byte[] getRange(byte[] key, long start, long end) {
   try {
     if (isPipelined()) {
       pipeline(pipeline.getrange(key, start, end));
       return null;
     }
     return client.getrange(key, start, end).data();
   } catch (Exception ex) {
     throw convertSrpAccessException(ex);
   }
 }