Exemplo n.º 1
0
 private List<Object> processMultiBulkReply(final RedisInputStream is) {
   int num = Integer.parseInt(is.readLine());
   if (num == -1) {
     return null;
   }
   List<Object> ret = new ArrayList<Object>(num);
   for (int i = 0; i < num; i++) {
     ret.add(process(is));
   }
   return ret;
 }
Exemplo n.º 2
0
  private byte[] processBulkReply(final RedisInputStream is) {
    int len = Integer.parseInt(is.readLine());
    if (len == -1) {
      return null;
    }
    byte[] read = new byte[len];
    int offset = 0;
    try {
      while (offset < len) {
        offset += is.read(read, offset, (len - offset));
      }
      // read 2 more bytes for the command delimiter
      is.readByte();
      is.readByte();
    } catch (IOException e) {
      throw new JedisConnectionException("protocol -> processBulkReply IOException");
    }

    return read;
  }
Exemplo n.º 3
0
 public void disconnect() {
   if (isConnected()) {
     try {
       inputStream.close();
       outputStream.close();
       if (channel.isOpen()) {
         channel.close();
       }
     } catch (IOException ex) {
       throw new JedisConnectionException(ex);
     }
   }
 }
Exemplo n.º 4
0
 public void disconnect() {
   if (isConnected()) {
     try {
       inputStream.close();
       outputStream.close();
       if (!socket.isClosed()) {
         socket.close();
       }
       if (pumpThread != null) {
         pumpThread.interrupt();
         pumpThread.join();
       }
     } catch (IOException ex) {
       throw new JedisConnectionException(ex);
     } catch (InterruptedException ie) {
       // throw?
     }
   }
 }
Exemplo n.º 5
0
 private Object process(final RedisInputStream is) {
   try {
     byte b = is.readByte();
     if (b == MINUS_BYTE) {
       processError(is);
     } else if (b == ASTERISK_BYTE) {
       return processMultiBulkReply(is);
     } else if (b == COLON_BYTE) {
       return processInteger(is);
     } else if (b == DOLLAR_BYTE) {
       return processBulkReply(is);
     } else if (b == PLUS_BYTE) {
       return processStatusCodeReply(is);
     } else {
       throw new JedisConnectionException("Unknown reply: " + (char) b);
     }
   } catch (IOException e) {
     throw new JedisConnectionException("process IOException " + e.getMessage());
   }
   return null;
 }
Exemplo n.º 6
0
 private byte[] processStatusCodeReply(final RedisInputStream is) {
   return SafeEncoder.encode(is.readLine());
 }
Exemplo n.º 7
0
 private void processError(final RedisInputStream is) {
   String message = is.readLine();
   throw new JedisDataException(message);
 }
Exemplo n.º 8
0
 private Long processInteger(final RedisInputStream is) {
   String num = is.readLine();
   return Long.valueOf(num);
 }