Java 类redis.clients.jedis.commands.ProtocolCommand 实例源码

项目:cachecloud    文件:ConnectionTest.java   
@Test
public void getErrorAfterConnectionReset() throws Exception {
  class TestConnection extends Connection {
    public TestConnection() {
      super("localhost", 6379);
    }

    @Override
    protected Connection sendCommand(ProtocolCommand cmd, byte[]... args) {
      return super.sendCommand(cmd, args);
    }
  }

  TestConnection conn = new TestConnection();

  try {
    conn.sendCommand(Command.HMSET, new byte[1024 * 1024 + 1][0]);
    fail("Should throw exception");
  } catch (JedisConnectionException jce) {
    assertEquals("ERR Protocol error: invalid multibulk length", jce.getMessage());
  }
}
项目:Jedis    文件:ConnectionTest.java   
@Test
public void getErrorAfterConnectionReset() throws Exception {
  class TestConnection extends Connection {
    public TestConnection() {
      super("localhost", 6379);
    }

    @Override
    protected Connection sendCommand(ProtocolCommand cmd, byte[]... args) {
      return super.sendCommand(cmd, args);
    }
  }

  TestConnection conn = new TestConnection();

  try {
    conn.sendCommand(Command.HMSET, new byte[1024 * 1024 + 1][0]);
    fail("Should throw exception");
  } catch (JedisConnectionException jce) {
    assertEquals("ERR Protocol error: invalid multibulk length", jce.getMessage());
  }
}
项目:cachecloud    文件:Connection.java   
protected Connection sendCommand(final ProtocolCommand 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);
}
项目:cachecloud    文件:Connection.java   
protected Connection sendCommand(final ProtocolCommand cmd, final byte[]... args) {
  try {
    //统计开始
    UsefulDataModel costModel = UsefulDataModel.getCostModel(threadLocal);
    costModel.setCommand(cmd.toString().toLowerCase());
    costModel.setStartTime(System.currentTimeMillis());

    connect();
    Protocol.sendCommand(outputStream, cmd, args);
    return this;
  } catch (JedisConnectionException ex) {
      UsefulDataCollector.collectException(ex, getHostPort(), System.currentTimeMillis());
    /*
     * When client send request which formed by invalid protocol, Redis send back error message
     * before close connection. We try to read it to provide reason of failure.
     */
    try {
      String errorMessage = Protocol.readErrorLineIfPossible(inputStream);
      if (errorMessage != null && errorMessage.length() > 0) {
        ex = new JedisConnectionException(errorMessage, ex.getCause());
      }
    } catch (Exception e) {
      /*
       * Catch any IOException or JedisConnectionException occurred from InputStream#read and just
       * ignore. This approach is safe because reading error message is optional and connection
       * will eventually be closed.
       */
    }
    // Any other exceptions related to connection?
    broken = true;
    throw ex;
  }
}
项目:Jedis    文件:Connection.java   
protected Connection sendCommand(final ProtocolCommand 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);
}
项目:Jedis    文件:Connection.java   
protected Connection sendCommand(final ProtocolCommand cmd, final byte[]... args) {
  try {
    connect();
    Protocol.sendCommand(outputStream, cmd, args);
    return this;
  } catch (JedisConnectionException ex) {
    /*
     * When client send request which formed by invalid protocol, Redis send back error message
     * before close connection. We try to read it to provide reason of failure.
     */
    try {
      String errorMessage = Protocol.readErrorLineIfPossible(inputStream);
      if (errorMessage != null && errorMessage.length() > 0) {
        ex = new JedisConnectionException(errorMessage, ex.getCause());
      }
    } catch (Exception e) {
      /*
       * Catch any IOException or JedisConnectionException occurred from InputStream#read and just
       * ignore. This approach is safe because reading error message is optional and connection
       * will eventually be closed.
       */
    }
    // Any other exceptions related to connection?
    broken = true;
    throw ex;
  }
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getCreateCommand() {
    return Command.CREATE;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getAddCommand() {
    return Command.ADD;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getAddHashCommand() {
    return Command.ADDHASH;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getDelCommand() {
    return Command.DEL;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getInfoCommand() {
    return Command.INFO;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getDropCommand() {
    return Command.DROP;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getSearchCommand() {
    return Command.SEARCH;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getOptimizeCommand() {
    return Command.OPTIMIZE;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getCreateCommand() {
    return ClusterCommand.CREATE;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getAddCommand() {
    return ClusterCommand.ADD;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getAddHashCommand() {
    return ClusterCommand.ADDHASH;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getDelCommand() {
    return ClusterCommand.DEL;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getInfoCommand() {
    return ClusterCommand.INFO;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getDropCommand() {
    return ClusterCommand.DROP;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getSearchCommand() {
    return ClusterCommand.SEARCH;
}
项目:JRediSearch    文件:Commands.java   
@Override
public ProtocolCommand getOptimizeCommand() {
    return ClusterCommand.OPTIMIZE;
}
项目:cachecloud    文件:Connection.java   
protected Connection sendCommand(final ProtocolCommand cmd) {
  return sendCommand(cmd, EMPTY_ARGS);
}
项目:cachecloud    文件:Protocol.java   
public static void sendCommand(final RedisOutputStream os, final ProtocolCommand command,
    final byte[]... args) {
  sendCommand(os, command.getRaw(), args);
}
项目:Jedis    文件:Connection.java   
protected Connection sendCommand(final ProtocolCommand cmd) {
  return sendCommand(cmd, EMPTY_ARGS);
}
项目:Jedis    文件:Protocol.java   
public static void sendCommand(final RedisOutputStream os, final ProtocolCommand command,
    final byte[]... args) {
  sendCommand(os, command.getRaw(), args);
}
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getCreateCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getAddCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getAddHashCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getDelCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getInfoCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getDropCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getSearchCommand();
项目:JRediSearch    文件:Commands.java   
ProtocolCommand getOptimizeCommand();