Exemplo n.º 1
0
 @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);
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 public List<Object> getAll(int except) {
   List<Object> all = new ArrayList<Object>();
   flush();
   while (pipelinedCommands > except) {
     all.add(protocol.read(inputStream));
     pipelinedCommands--;
   }
   return all;
 }
Exemplo n.º 4
0
 protected String getStatusCodeReply() {
   flush();
   pipelinedCommands--;
   final byte[] resp = (byte[]) protocol.read(inputStream);
   if (null == resp) {
     return null;
   } else {
     return SafeEncoder.encode(resp);
   }
 }
Exemplo n.º 5
0
 @Test
 public void busyReply() {
   final String busyMessage = "BUSY Redis is busy running a script.";
   final InputStream is = new ByteArrayInputStream(('-' + busyMessage + "\r\n").getBytes());
   try {
     Protocol.read(new RedisInputStream(is));
   } catch (final JedisBusyException e) {
     assertEquals(busyMessage, e.getMessage());
     return;
   }
   fail("Expected a JedisBusyException to be thrown.");
 }
Exemplo n.º 6
0
 public List<Object> getAll(int except) {
   List<Object> all = new ArrayList<Object>();
   flush();
   while (pipelinedCommands > except) {
     try {
       all.add(Protocol.read(inputStream));
     } catch (JedisDataException e) {
       all.add(e);
     }
     pipelinedCommands--;
   }
   return all;
 }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
0
    @Override
    public void run() {
      JedisDataException exception = null;
      try {
        while (isConnected()) {
          Response<?> response = asyncResponses.take();
          Object data = Protocol.read(inputStream);
          response.set(data);
          wakeNextWriter();
        }

      } catch (Exception ioe) {
        exception = new JedisDataException(ioe);
      }
      if (exception == null) {
        exception = new JedisDataException("Disconnected");
      }
      // if something went wrong
      Response<?> response;
      while ((response = asyncResponses.poll()) != null) {
        response.set(exception);
      }
    }
Exemplo n.º 9
0
 @Test
 public void nullBulkReply() {
   InputStream is = new ByteArrayInputStream("$-1\r\n".getBytes());
   String response = (String) Protocol.read(new RedisInputStream(is));
   assertEquals(null, response);
 }
Exemplo n.º 10
0
 @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);
 }
Exemplo n.º 11
0
 @SuppressWarnings("unchecked")
 public List<Object> getObjectMultiBulkReply() {
   flush();
   pipelinedCommands--;
   return (List<Object>) protocol.read(inputStream);
 }
Exemplo n.º 12
0
 public Long getIntegerReply() {
   flush();
   pipelinedCommands--;
   return (Long) protocol.read(inputStream);
 }
Exemplo n.º 13
0
 public byte[] getBinaryBulkReply() {
   flush();
   pipelinedCommands--;
   return (byte[]) protocol.read(inputStream);
 }
Exemplo n.º 14
0
 public Object getOne() {
   waitForAsyncReadsToComplete();
   flush();
   pipelinedCommands--;
   return Protocol.read(inputStream);
 }
Exemplo n.º 15
0
 @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);
 }
Exemplo n.º 16
0
 public Object getOne() {
   flush();
   pipelinedCommands--;
   return protocol.read(inputStream);
 }
Exemplo n.º 17
0
 @Test
 public void integerReply() {
   InputStream is = new ByteArrayInputStream(":123\r\n".getBytes());
   long response = (Long) Protocol.read(new RedisInputStream(is));
   assertEquals(123, response);
 }
Exemplo n.º 18
0
 @SuppressWarnings("deprecation")
 public Double getDoubleReply() {
   flush();
   pipelinedCommands--;
   return Double.valueOf(new String((byte[]) Protocol.read(inputStream)));
 }