Beispiel #1
0
 public void sdiffstore(final String dstkey, final String... keys) {
   final byte[][] bkeys = new byte[keys.length][];
   for (int i = 0; i < bkeys.length; i++) {
     bkeys[i] = SafeEncoder.encode(keys[i]);
   }
   sdiffstore(SafeEncoder.encode(dstkey), bkeys);
 }
Beispiel #2
0
 public void zinterstore(final String dstkey, final ZParams params, final String... sets) {
   final byte[][] bsets = new byte[sets.length][];
   for (int i = 0; i < bsets.length; i++) {
     bsets[i] = SafeEncoder.encode(sets[i]);
   }
   zinterstore(SafeEncoder.encode(dstkey), params, bsets);
 }
Beispiel #3
0
 public void hmget(final String key, final String... fields) {
   final byte[][] bfields = new byte[fields.length][];
   for (int i = 0; i < bfields.length; i++) {
     bfields[i] = SafeEncoder.encode(fields[i]);
   }
   hmget(SafeEncoder.encode(key), bfields);
 }
Beispiel #4
0
 public void hmset(final String key, final Map<String, String> hash) {
   final Map<byte[], byte[]> bhash = new HashMap<byte[], byte[]>(hash.size());
   for (final Entry<String, String> entry : hash.entrySet()) {
     bhash.put(SafeEncoder.encode(entry.getKey()), SafeEncoder.encode(entry.getValue()));
   }
   hmset(SafeEncoder.encode(key), bhash);
 }
Beispiel #5
0
 public void cluster(final String subcommand, final String... args) {
   final byte[][] arg = new byte[args.length + 1][];
   for (int i = 1; i < arg.length; i++) {
     arg[i] = SafeEncoder.encode(args[i - 1]);
   }
   arg[0] = SafeEncoder.encode(subcommand);
   cluster(arg);
 }
Beispiel #6
0
 @Override
 public void zunionstore(final String dstkey, final String... sets) {
   final byte[][] bsets = new byte[sets.length][];
   for (int i = 0; i < bsets.length; i++) {
     bsets[i] = SafeEncoder.encode(sets[i]);
   }
   zunionstore(SafeEncoder.encode(dstkey), bsets);
 }
Beispiel #7
0
 public void migrate(
     final String host,
     final int port,
     final String key,
     final int destinationDb,
     final int timeout) {
   migrate(SafeEncoder.encode(host), port, SafeEncoder.encode(key), destinationDb, timeout);
 }
Beispiel #8
0
 @Override
 public void bitfield(final String key, final String... arguments) {
   byte[][] argumentArray = new byte[arguments.length][];
   int index = 0;
   for (String argument : arguments) {
     argumentArray[index++] = SafeEncoder.encode(argument);
   }
   bitfield(SafeEncoder.encode(key), argumentArray);
 }
Beispiel #9
0
  public void zadd(String key, Map<Double, String> scoreMembers) {
    HashMap<Double, byte[]> binaryScoreMembers = new HashMap<Double, byte[]>();

    for (Map.Entry<Double, String> entry : scoreMembers.entrySet()) {
      binaryScoreMembers.put(entry.getKey(), SafeEncoder.encode(entry.getValue()));
    }

    zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
  }
 @Override
 public void hSetKey(String key, String field, byte[] value) {
   Jedis redis = pool.getResource();
   try {
     redis.hset(SafeEncoder.encode(key), SafeEncoder.encode(field), value);
   } catch (JedisException je) {
     logger.error("Error when set K:" + key + "-F:" + field + "-V:" + value, je);
     je.printStackTrace();
   } finally {
     redis.close();
   }
 }
 @Override
 public byte[] hGetWiseValue(String key, String field) {
   byte[] v = null;
   Jedis redis = pool.getResource();
   try {
     v = redis.hget(SafeEncoder.encode(key), SafeEncoder.encode(field));
   } catch (JedisException je) {
     logger.error("Error when get K:" + key + "-F:" + field + "-V:", je);
     je.printStackTrace();
   } finally {
     redis.close();
   }
   return v;
 }
Beispiel #12
0
  @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"));

    assertEquals(expected, response);
  }
Beispiel #13
0
 public void brpop(final String[] args) {
   final byte[][] bargs = new byte[args.length][];
   for (int i = 0; i < bargs.length; i++) {
     bargs[i] = SafeEncoder.encode(args[i]);
   }
   brpop(bargs);
 }
Beispiel #14
0
 public void scriptExists(String... sha1) {
   final byte[][] bsha1 = new byte[sha1.length][];
   for (int i = 0; i < bsha1.length; i++) {
     bsha1[i] = SafeEncoder.encode(sha1[i]);
   }
   scriptExists(bsha1);
 }
Beispiel #15
0
 public void sentinel(final String... args) {
   final byte[][] arg = new byte[args.length][];
   for (int i = 0; i < arg.length; i++) {
     arg[i] = SafeEncoder.encode(args[i]);
   }
   sentinel(arg);
 }
Beispiel #16
0
 public void punsubscribe(final String... patterns) {
   final byte[][] ps = new byte[patterns.length][];
   for (int i = 0; i < ps.length; i++) {
     ps[i] = SafeEncoder.encode(patterns[i]);
   }
   punsubscribe(ps);
 }
Beispiel #17
0
 public void subscribe(final String... channels) {
   final byte[][] cs = new byte[channels.length][];
   for (int i = 0; i < cs.length; i++) {
     cs[i] = SafeEncoder.encode(channels[i]);
   }
   subscribe(cs);
 }
  private long incrementValue(byte[] value, long increment) {
    String numberEncode = SafeEncoder.encode(value);
    long longValue = Long.parseLong(numberEncode);
    longValue += increment;

    return longValue;
  }
Beispiel #19
0
 public void del(final String... keys) {
   final byte[][] bkeys = new byte[keys.length][];
   for (int i = 0; i < keys.length; i++) {
     bkeys[i] = SafeEncoder.encode(keys[i]);
   }
   del(bkeys);
 }
Beispiel #20
0
 protected Connection sendCommand(final Command cmd, final String... args) {
   final byte[][] bargs = new byte[args.length][];
   for (int i = 0; i < args.length; i++) {
     bargs[i] = SafeEncoder.encode(args[i]);
   }
   return sendCommand(cmd, bargs);
 }
Beispiel #21
0
 @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);
 }
Beispiel #22
0
 public String getElement() {
   if (null != element) {
     return SafeEncoder.encode(element);
   } else {
     return null;
   }
 }
  /**
   * Sets or clears the bit at offset in the string value stored at key
   *
   * @param key
   * @param offset
   * @param value
   * @return
   */
  public Boolean setbit(byte[] key, long offset, byte[] value) {

    boolean originalValue = getbit(key, offset);

    int realValue = Integer.parseInt(SafeEncoder.encode(value));

    int numberOfBytesRequired = BitsUtils.calculateNumberOfBytes((int) offset);
    if (simpleTypes.containsKey(wrap(key))) {

      byte[] currentValue = simpleTypes.get(wrap(key)).array();

      if (numberOfBytesRequired > currentValue.length) {
        currentValue =
            BitsUtils.extendByteArrayBy(currentValue, numberOfBytesRequired - currentValue.length);
      }

      BitsUtils.setBit(currentValue, (int) offset, realValue);
      simpleTypes.put(wrap(key), wrap(currentValue));

      return originalValue;

    } else {
      byte[] values = new byte[numberOfBytesRequired];
      BitsUtils.setBit(values, (int) offset, realValue);
      simpleTypes.put(wrap(key), wrap(values));

      return Boolean.FALSE;
    }
  }
Beispiel #24
0
 public void watch(final String... keys) {
   final byte[][] bargs = new byte[keys.length][];
   for (int i = 0; i < bargs.length; i++) {
     bargs[i] = SafeEncoder.encode(keys[i]);
   }
   watch(bargs);
 }
Beispiel #25
0
 public void mset(final String... keysvalues) {
   final byte[][] bkeysvalues = new byte[keysvalues.length][];
   for (int i = 0; i < keysvalues.length; i++) {
     bkeysvalues[i] = SafeEncoder.encode(keysvalues[i]);
   }
   mset(bkeysvalues);
 }
Beispiel #26
0
 @Override
 public void sdiff(final String... keys) {
   final byte[][] bkeys = new byte[keys.length][];
   for (int i = 0; i < bkeys.length; i++) {
     bkeys[i] = SafeEncoder.encode(keys[i]);
   }
   sdiff(bkeys);
 }
Beispiel #27
0
 public String getBulkReply() {
   final byte[] result = getBinaryBulkReply();
   if (null != result) {
     return SafeEncoder.encode(result);
   } else {
     return null;
   }
 }
Beispiel #28
0
  private HashMap<byte[], Double> convertScoreMembersToBinary(Map<String, Double> scoreMembers) {
    HashMap<byte[], Double> binaryScoreMembers = new HashMap<byte[], Double>();

    for (Entry<String, Double> entry : scoreMembers.entrySet()) {
      binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()), entry.getValue());
    }
    return binaryScoreMembers;
  }
Beispiel #29
0
 protected String getStatusCodeReply() {
   final byte[] resp = (byte[]) getOne();
   if (null == resp) {
     return null;
   } else {
     return SafeEncoder.encode(resp);
   }
 }
  private long incrementAndSetValue(final byte[] key, final long integer) {
    byte[] oldValue = simpleTypes.get(wrap(key)).array();
    long newValue = incrementValue(oldValue, integer);
    byte[] newValueByteArray = SafeEncoder.encode(Long.toString(newValue));
    simpleTypes.put(wrap(key), wrap(newValueByteArray));

    return newValue;
  }