All Downloads are FREE. Search and download functionalities are using the official Maven repository.

redis.clients.jedis.resps.Slowlog Maven / Gradle / Ivy

The newest version!
package redis.clients.jedis.resps;

import java.util.ArrayList;
import java.util.List;
import redis.clients.jedis.BuilderFactory;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.util.SafeEncoder;

public class Slowlog {

  private final long id;
  private final long timeStamp;
  private final long executionTime;
  private final List args;
  private HostAndPort clientIpPort;
  private String clientName;

  private static final String COMMA = ",";

  @SuppressWarnings("unchecked")
  private Slowlog(List properties) {
    this.id = (Long) properties.get(0);
    this.timeStamp = (Long) properties.get(1);
    this.executionTime = (Long) properties.get(2);

    this.args = BuilderFactory.STRING_LIST.build(properties.get(3));
    if (properties.size() == 4) return;

    this.clientIpPort = HostAndPort.from(SafeEncoder.encode((byte[]) properties.get(4)));
    this.clientName = SafeEncoder.encode((byte[]) properties.get(5));
  }

  @SuppressWarnings("unchecked")
  public static List from(List nestedMultiBulkReply) {
    List logs = new ArrayList<>(nestedMultiBulkReply.size());
    for (Object obj : nestedMultiBulkReply) {
      List properties = (List) obj;
      logs.add(new Slowlog(properties));
    }
    return logs;
  }

  public long getId() {
    return id;
  }

  public long getTimeStamp() {
    return timeStamp;
  }

  public long getExecutionTime() {
    return executionTime;
  }

  public List getArgs() {
    return args;
  }

  public HostAndPort getClientIpPort() {
    return clientIpPort;
  }

  public String getClientName() {
    return clientName;
  }

  @Override
  public String toString() {
    return new StringBuilder().append(id).append(COMMA).append(timeStamp).append(COMMA)
        .append(executionTime).append(COMMA).append(args).toString();
  }
}