jedis源码阅读

package redis.clients.jedis;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import redis.clients.util.SafeEncoder;
import redis.clients.util.Slowlog;

public class Jedis extends BinaryJedis implements JedisCommands
{
  public Jedis(String host)
  {
    super(host);
  }

  public Jedis(String host, int port) {
    super(host, port);
  }

  public Jedis(String host, int port, int timeout) {
    super(host, port, timeout);
  }

  public Jedis(JedisShardInfo shardInfo) {
    super(shardInfo);
  }

  public String ping() {
    checkIsInMulti();
    this.client.ping();
    return this.client.getStatusCodeReply();
  }

  public String set(String key, String value)
  {
    checkIsInMulti();
    this.client.set(key, value);
    return this.client.getStatusCodeReply();
  }

  public String get(String key)
  {
    checkIsInMulti();
    this.client.sendCommand(Protocol.Command.GET, new String[] { key });
    return this.client.getBulkReply();
  }

  public String quit()
  {
    checkIsInMulti();
    this.client.quit();
    return this.client.getStatusCodeReply();
  }

  public Boolean exists(String key)
  {
    checkIsInMulti();
    this.client.exists(key);
    return Boolean.valueOf(this.client.getIntegerReply().longValue() == 1L);
  }

  public Long del(String... keys)
  {
    checkIsInMulti();
    this.client.del(keys);
    return this.client.getIntegerReply();
  }

  public String type(String key)
  {
    checkIsInMulti();
    this.client.type(key);
    return this.client.getStatusCodeReply();
  }

  public String flushDB()
  {
    checkIsInMulti();
    this.client.flushDB();
    return this.client.getStatusCodeReply();
  }

  public Set<String> keys(String pattern)
  {
    checkIsInMulti();
    this.client.keys(pattern);
    return (Set)BuilderFactory.STRING_SET.build(this.client.getBinaryMultiBulkReply());
  }

  public String randomKey()
  {
    checkIsInMulti();
    this.client.randomKey();
    return this.client.getBulkReply();
  }

  public String rename(String oldkey, String newkey)
  {
    checkIsInMulti();
    this.client.rename(oldkey, newkey);
    return this.client.getStatusCodeReply();
  }

  public Long renamenx(String oldkey, String newkey)
  {
    checkIsInMulti();
    this.client.renamenx(oldkey, newkey);
    return this.client.getIntegerReply();
  }

  public Long expire(String key, int seconds)
  {
    checkIsInMulti();
    this.client.expire(key, seconds);
    return this.client.getIntegerReply();
  }

  public Long expireAt(String key, long unixTime)
  {
    checkIsInMulti();
    this.client.expireAt(key, unixTime);
    return this.client.getIntegerReply();
  }

  public Long ttl(String key)
  {
    checkIsInMulti();
    this.client.ttl(key);
    return this.client.getIntegerReply();
  }

  public String select(int index)
  {
    checkIsInMulti();
    this.client.select(index);
    return this.client.getStatusCodeReply();
  }

  public Long move(String key, int dbIndex)
  {
    checkIsInMulti();
    this.client.move(key, dbIndex);
    return this.client.getIntegerReply();
  }

  public String flushAll()
  {
    checkIsInMulti();
    this.client.flushAll();
    return this.client.getStatusCodeReply();
  }

  public String getSet(String key, String value)
  {
    checkIsInMulti();
    this.client.getSet(key, value);
    return this.client.getBulkReply();
  }

  public List<String> mget(String... keys)
  {
    checkIsInMulti();
    this.client.mget(keys);
    return this.client.getMultiBulkReply();
  }

  public Long setnx(String key, String value)
  {
    checkIsInMulti();
    this.client.setnx(key, value);
    return this.client.getIntegerReply();
  }

  public String setex(String key, int seconds, String value)
  {
    checkIsInMulti();
    this.client.setex(key, seconds, value);
    return this.client.getStatusCodeReply();
  }

  public String mset(String... keysvalues)
  {
    checkIsInMulti();
    this.client.mset(keysvalues);
    return this.client.getStatusCodeReply();
  }

  public Long msetnx(String... keysvalues)
  {
    checkIsInMulti();
    this.client.msetnx(keysvalues);
    return this.client.getIntegerReply();
  }

  public Long decrBy(String key, long integer)
  {
    checkIsInMulti();
    this.client.decrBy(key, integer);
    return this.client.getIntegerReply();
  }

  public Long decr(String key)
  {
    checkIsInMulti();
    this.client.decr(key);
    return this.client.getIntegerReply();
  }

  public Long incrBy(String key, long integer)
  {
    checkIsInMulti();
    this.client.incrBy(key, integer);
    return this.client.getIntegerReply();
  }

  public Long incr(String key)
  {
    checkIsInMulti();
    this.client.incr(key);
    return this.client.getIntegerReply();
  }

  public Long append(String key, String value)
  {
    checkIsInMulti();
    this.client.append(key, value);
    return this.client.getIntegerReply();
  }

  public String substr(String key, int start, int end)
  {
    checkIsInMulti();
    this.client.substr(key, start, end);
    return this.client.getBulkReply();
  }

  public Long hset(String key, String field, String value)
  {
    checkIsInMulti();
    this.client.hset(key, field, value);
    return this.client.getIntegerReply();
  }

  public String hget(String key, String field)
  {
    checkIsInMulti();
    this.client.hget(key, field);
    return this.client.getBulkReply();
  }

  public Long hsetnx(String key, String field, String value)
  {
    checkIsInMulti();
    this.client.hsetnx(key, field, value);
    return this.client.getIntegerReply();
  }

  public String hmset(String key, Map<String, String> hash)
  {
    checkIsInMulti();
    this.client.hmset(key, hash);
    return this.client.getStatusCodeReply();
  }

  public List<String> hmget(String key, String... fields)
  {
    checkIsInMulti();
    this.client.hmget(key, fields);
    return this.client.getMultiBulkReply();
  }

  public Long hincrBy(String key, String field, long value)
  {
    checkIsInMulti();
    this.client.hincrBy(key, field, value);
    return this.client.getIntegerReply();
  }

  public Boolean hexists(String key, String field)
  {
    checkIsInMulti();
    this.client.hexists(key, field);
    return Boolean.valueOf(this.client.getIntegerReply().longValue() == 1L);
  }

  public Long hdel(String key, String... fields)
  {
    checkIsInMulti();
    this.client.hdel(key, fields);
    return this.client.getIntegerReply();
  }

  public Long hlen(String key)
  {
    checkIsInMulti();
    this.client.hlen(key);
    return this.client.getIntegerReply();
  }

  public Set<String> hkeys(String key)
  {
    checkIsInMulti();
    this.client.hkeys(key);
    return (Set)BuilderFactory.STRING_SET.build(this.client.getBinaryMultiBulkReply());
  }

  public List<String> hvals(String key)
  {
    checkIsInMulti();
    this.client.hvals(key);
    List<String> lresult = this.client.getMultiBulkReply();
    return lresult;
  }

  public Map<String, String> hgetAll(String key)
  {
    checkIsInMulti();
    this.client.hgetAll(key);
    return (Map)BuilderFactory.STRING_MAP.build(this.client.getBinaryMultiBulkReply());
  }

  public Long rpush(String key, String... strings)
  {
    checkIsInMulti();
    this.client.rpush(key, strings);
    return this.client.getIntegerReply();
  }

  public Long lpush(String key, String... strings)
  {
    checkIsInMulti();
    this.client.lpush(key, strings);
    return this.client.getIntegerReply();
  }

  public Long llen(String key)
  {
    checkIsInMulti();
    this.client.llen(key);
    return this.client.getIntegerReply();
  }

  public List<String> lrange(String key, long start, long end)
  {
    checkIsInMulti();
    this.client.lrange(key, start, end);
    return this.client.getMultiBulkReply();
  }

  public String ltrim(String key, long start, long end)
  {
    checkIsInMulti();
    this.client.ltrim(key, start, end);
    return this.client.getStatusCodeReply();
  }

  public String lindex(String key, long index)
  {
    checkIsInMulti();
    this.client.lindex(key, index);
    return this.client.getBulkReply();
  }

  public String lset(String key, long index, String value)
  {
    checkIsInMulti();
    this.client.lset(key, index, value);
    return this.client.getStatusCodeReply();
  }

  public Long lrem(String key, long count, String value)
  {
    checkIsInMulti();
    this.client.lrem(key, count, value);
    return this.client.getIntegerReply();
  }

  public String lpop(String key)
  {
    checkIsInMulti();
    this.client.lpop(key);
    return this.client.getBulkReply();
  }

  public String rpop(String key)
  {
    checkIsInMulti();
    this.client.rpop(key);
    return this.client.getBulkReply();
  }

  public String rpoplpush(String srckey, String dstkey)
  {
    checkIsInMulti();
    this.client.rpoplpush(srckey, dstkey);
    return this.client.getBulkReply();
  }

  public Long sadd(String key, String... members)
  {
    checkIsInMulti();
    this.client.sadd(key, members);
    return this.client.getIntegerReply();
  }

  public Set<String> smembers(String key)
  {
    checkIsInMulti();
    this.client.smembers(key);
    List<String> members = this.client.getMultiBulkReply();
    return new HashSet(members);
  }

  public Long srem(String key, String... members)
  {
    checkIsInMulti();
    this.client.srem(key, members);
    return this.client.getIntegerReply();
  }

  public String spop(String key)
  {
    checkIsInMulti();
    this.client.spop(key);
    return this.client.getBulkReply();
  }

  public Long smove(String srckey, String dstkey, String member)
  {
    checkIsInMulti();
    this.client.smove(srckey, dstkey, member);
    return this.client.getIntegerReply();
  }

  public Long scard(String key)
  {
    checkIsInMulti();
    this.client.scard(key);
    return this.client.getIntegerReply();
  }

  public Boolean sismember(String key, String member)
  {
    checkIsInMulti();
    this.client.sismember(key, member);
    return Boolean.valueOf(this.client.getIntegerReply().longValue() == 1L);
  }

  public Set<String> sinter(String... keys)
  {
    checkIsInMulti();
    this.client.sinter(keys);
    List<String> members = this.client.getMultiBulkReply();
    return new HashSet(members);
  }

  public Long sinterstore(String dstkey, String... keys)
  {
    checkIsInMulti();
    this.client.sinterstore(dstkey, keys);
    return this.client.getIntegerReply();
  }

  public Set<String> sunion(String... keys)
  {
    checkIsInMulti();
    this.client.sunion(keys);
    List<String> members = this.client.getMultiBulkReply();
    return new HashSet(members);
  }

  public Long sunionstore(String dstkey, String... keys)
  {
    checkIsInMulti();
    this.client.sunionstore(dstkey, keys);
    return this.client.getIntegerReply();
  }

  public Set<String> sdiff(String... keys)
  {
    checkIsInMulti();
    this.client.sdiff(keys);
    return (Set)BuilderFactory.STRING_SET.build(this.client.getBinaryMultiBulkReply());
  }

  public Long sdiffstore(String dstkey, String... keys)
  {
    checkIsInMulti();
    this.client.sdiffstore(dstkey, keys);
    return this.client.getIntegerReply();
  }

  public String srandmember(String key)
  {
    checkIsInMulti();
    this.client.srandmember(key);
    return this.client.getBulkReply();
  }

  public Long zadd(String key, double score, String member)
  {
    checkIsInMulti();
    this.client.zadd(key, score, member);
    return this.client.getIntegerReply();
  }

  public Long zadd(String key, Map<Double, String> scoreMembers) {
    checkIsInMulti();
    this.client.zadd(key, scoreMembers);
    return this.client.getIntegerReply();
  }

  public Set<String> zrange(String key, long start, long end) {
    checkIsInMulti();
    this.client.zrange(key, start, end);
    List<String> members = this.client.getMultiBulkReply();
    return new LinkedHashSet(members);
  }

  public Long zrem(String key, String... members)
  {
    checkIsInMulti();
    this.client.zrem(key, members);
    return this.client.getIntegerReply();
  }

  public Double zincrby(String key, double score, String member)
  {
    checkIsInMulti();
    this.client.zincrby(key, score, member);
    String newscore = this.client.getBulkReply();
    return Double.valueOf(newscore);
  }

  public Long zrank(String key, String member)
  {
    checkIsInMulti();
    this.client.zrank(key, member);
    return this.client.getIntegerReply();
  }

  public Long zrevrank(String key, String member)
  {
    checkIsInMulti();
    this.client.zrevrank(key, member);
    return this.client.getIntegerReply();
  }

  public Set<String> zrevrange(String key, long start, long end)
  {
    checkIsInMulti();
    this.client.zrevrange(key, start, end);
    List<String> members = this.client.getMultiBulkReply();
    return new LinkedHashSet(members);
  }

  public Set<Tuple> zrangeWithScores(String key, long start, long end)
  {
    checkIsInMulti();
    this.client.zrangeWithScores(key, start, end);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<Tuple> zrevrangeWithScores(String key, long start, long end)
  {
    checkIsInMulti();
    this.client.zrevrangeWithScores(key, start, end);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Long zcard(String key)
  {
    checkIsInMulti();
    this.client.zcard(key);
    return this.client.getIntegerReply();
  }

  public Double zscore(String key, String member)
  {
    checkIsInMulti();
    this.client.zscore(key, member);
    String score = this.client.getBulkReply();
    return score != null ? new Double(score) : null;
  }

  public String watch(String... keys) {
    this.client.watch(keys);
    return this.client.getStatusCodeReply();
  }

  public List<String> sort(String key)
  {
    checkIsInMulti();
    this.client.sort(key);
    return this.client.getMultiBulkReply();
  }

  public List<String> sort(String key, SortingParams sortingParameters)
  {
    checkIsInMulti();
    this.client.sort(key, sortingParameters);
    return this.client.getMultiBulkReply();
  }

  public List<String> blpop(int timeout, String... keys)
  {
    checkIsInMulti();
    List<String> args = new ArrayList();
    for (String arg : keys) {
      args.add(arg);
    }
    args.add(String.valueOf(timeout));

    this.client.blpop((String[])args.toArray(new String[args.size()]));
    this.client.setTimeoutInfinite();
    List<String> multiBulkReply = this.client.getMultiBulkReply();
    this.client.rollbackTimeout();
    return multiBulkReply;
  }

  public Long sort(String key, SortingParams sortingParameters, String dstkey)
  {
    checkIsInMulti();
    this.client.sort(key, sortingParameters, dstkey);
    return this.client.getIntegerReply();
  }

  public Long sort(String key, String dstkey)
  {
    checkIsInMulti();
    this.client.sort(key, dstkey);
    return this.client.getIntegerReply();
  }

  public List<String> brpop(int timeout, String... keys)
  {
    checkIsInMulti();
    List<String> args = new ArrayList();
    for (String arg : keys) {
      args.add(arg);
    }
    args.add(String.valueOf(timeout));

    this.client.brpop((String[])args.toArray(new String[args.size()]));
    this.client.setTimeoutInfinite();
    List<String> multiBulkReply = this.client.getMultiBulkReply();
    this.client.rollbackTimeout();

    return multiBulkReply;
  }

  public String auth(String password)
  {
    checkIsInMulti();
    this.client.auth(password);
    return this.client.getStatusCodeReply();
  }

  public void subscribe(JedisPubSub jedisPubSub, String... channels) {
    checkIsInMulti();
    connect();
    this.client.setTimeoutInfinite();
    jedisPubSub.proceed(this.client, channels);
    this.client.rollbackTimeout();
  }

  public Long publish(String channel, String message) {
    checkIsInMulti();
    this.client.publish(channel, message);
    return this.client.getIntegerReply();
  }

  public void psubscribe(JedisPubSub jedisPubSub, String... patterns) {
    checkIsInMulti();
    connect();
    this.client.setTimeoutInfinite();
    jedisPubSub.proceedWithPatterns(this.client, patterns);
    this.client.rollbackTimeout();
  }

  public Long zcount(String key, double min, double max) {
    checkIsInMulti();
    this.client.zcount(key, min, max);
    return this.client.getIntegerReply();
  }

  public Long zcount(String key, String min, String max) {
    checkIsInMulti();
    this.client.zcount(key, min, max);
    return this.client.getIntegerReply();
  }

  public Set<String> zrangeByScore(String key, double min, double max)
  {
    checkIsInMulti();
    this.client.zrangeByScore(key, min, max);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<String> zrangeByScore(String key, String min, String max)
  {
    checkIsInMulti();
    this.client.zrangeByScore(key, min, max);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<String> zrangeByScore(String key, double min, double max, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrangeByScore(key, min, max, offset, count);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<String> zrangeByScore(String key, String min, String max, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrangeByScore(key, min, max, offset, count);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max)
  {
    checkIsInMulti();
    this.client.zrangeByScoreWithScores(key, min, max);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max)
  {
    checkIsInMulti();
    this.client.zrangeByScoreWithScores(key, min, max);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrangeByScoreWithScores(key, min, max, offset, count);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrangeByScoreWithScores(key, min, max, offset, count);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  private Set<Tuple> getTupledSet() {
    checkIsInMulti();
    List<String> membersWithScores = this.client.getMultiBulkReply();
    Set<Tuple> set = new LinkedHashSet();
    Iterator<String> iterator = membersWithScores.iterator();
    while (iterator.hasNext()) {
      set.add(new Tuple((String)iterator.next(), Double.valueOf((String)iterator.next())));
    }
    return set;
  }

  public Set<String> zrevrangeByScore(String key, double max, double min)
  {
    checkIsInMulti();
    this.client.zrevrangeByScore(key, max, min);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<String> zrevrangeByScore(String key, String max, String min)
  {
    checkIsInMulti();
    this.client.zrevrangeByScore(key, max, min);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrevrangeByScore(key, max, min, offset, count);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min)
  {
    checkIsInMulti();
    this.client.zrevrangeByScoreWithScores(key, max, min);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrevrangeByScoreWithScores(key, max, min, offset, count);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrevrangeByScoreWithScores(key, max, min, offset, count);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Set<String> zrevrangeByScore(String key, String max, String min, int offset, int count)
  {
    checkIsInMulti();
    this.client.zrevrangeByScore(key, max, min, offset, count);
    return new LinkedHashSet(this.client.getMultiBulkReply());
  }

  public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min)
  {
    checkIsInMulti();
    this.client.zrevrangeByScoreWithScores(key, max, min);
    Set<Tuple> set = getTupledSet();
    return set;
  }

  public Long zremrangeByRank(String key, long start, long end)
  {
    checkIsInMulti();
    this.client.zremrangeByRank(key, start, end);
    return this.client.getIntegerReply();
  }

  public Long zremrangeByScore(String key, double start, double end)
  {
    checkIsInMulti();
    this.client.zremrangeByScore(key, start, end);
    return this.client.getIntegerReply();
  }

  public Long zremrangeByScore(String key, String start, String end)
  {
    checkIsInMulti();
    this.client.zremrangeByScore(key, start, end);
    return this.client.getIntegerReply();
  }

  public Long zunionstore(String dstkey, String... sets)
  {
    checkIsInMulti();
    this.client.zunionstore(dstkey, sets);
    return this.client.getIntegerReply();
  }

  public Long zunionstore(String dstkey, ZParams params, String... sets)
  {
    checkIsInMulti();
    this.client.zunionstore(dstkey, params, sets);
    return this.client.getIntegerReply();
  }

  public Long zinterstore(String dstkey, String... sets)
  {
    checkIsInMulti();
    this.client.zinterstore(dstkey, sets);
    return this.client.getIntegerReply();
  }

  public Long zinterstore(String dstkey, ZParams params, String... sets)
  {
    checkIsInMulti();
    this.client.zinterstore(dstkey, params, sets);
    return this.client.getIntegerReply();
  }

  public Long strlen(String key) {
    this.client.strlen(key);
    return this.client.getIntegerReply();
  }

  public Long lpushx(String key, String string) {
    this.client.lpushx(key, string);
    return this.client.getIntegerReply();
  }

  public Long persist(String key)
  {
    this.client.persist(key);
    return this.client.getIntegerReply();
  }

  public Long rpushx(String key, String string) {
    this.client.rpushx(key, string);
    return this.client.getIntegerReply();
  }

  public String echo(String string) {
    this.client.echo(string);
    return this.client.getBulkReply();
  }

  public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value)
  {
    this.client.linsert(key, where, pivot, value);
    return this.client.getIntegerReply();
  }

  public String brpoplpush(String source, String destination, int timeout)
  {
    this.client.brpoplpush(source, destination, timeout);
    this.client.setTimeoutInfinite();
    String reply = this.client.getBulkReply();
    this.client.rollbackTimeout();
    return reply;
  }

  public Boolean setbit(String key, long offset, boolean value)
  {
    this.client.setbit(key, offset, value);
    return Boolean.valueOf(this.client.getIntegerReply().longValue() == 1L);
  }

  public Boolean getbit(String key, long offset)
  {
    this.client.getbit(key, offset);
    return Boolean.valueOf(this.client.getIntegerReply().longValue() == 1L);
  }

  public Long setrange(String key, long offset, String value) {
    this.client.setrange(key, offset, value);
    return this.client.getIntegerReply();
  }

  public String getrange(String key, long startOffset, long endOffset) {
    this.client.getrange(key, startOffset, endOffset);
    return this.client.getBulkReply();
  }

  public List<String> configGet(String pattern)
  {
    this.client.configGet(pattern);
    return this.client.getMultiBulkReply();
  }

  public String configSet(String parameter, String value)
  {
    this.client.configSet(parameter, value);
    return this.client.getStatusCodeReply();
  }

  public Object eval(String script, int keyCount, String... params) {
    this.client.setTimeoutInfinite();
    this.client.eval(script, keyCount, params);

    return getEvalResult();
  }

  private String[] getParams(List<String> keys, List<String> args) {
    int keyCount = keys.size();
    int argCount = args.size();

    String[] params = new String[keyCount + args.size()];

    for (int i = 0; i < keyCount; i++) {
      params[i] = ((String)keys.get(i));
    }
    for (int i = 0; i < argCount; i++) {
      params[(keyCount + i)] = ((String)args.get(i));
    }
    return params;
  }

  public Object eval(String script, List<String> keys, List<String> args) {
    return eval(script, keys.size(), getParams(keys, args));
  }

  public Object eval(String script) {
    return eval(script, 0, new String[0]);
  }

  public Object evalsha(String script) {
    return evalsha(script, 0, new String[0]);
  }

  private Object getEvalResult() {
    Object result = this.client.getOne();

    if ((result instanceof byte[])) {
      return SafeEncoder.encode((byte[])result);
    }
    if ((result instanceof List)) {
      List<?> list = (List)result;
      List<String> listResult = new ArrayList(list.size());
      for (Iterator i$ = list.iterator(); i$.hasNext();) { Object bin = i$.next();
        listResult.add(SafeEncoder.encode((byte[])bin));
      }
      return listResult;
    }

    return result;
  }

  public Object evalsha(String sha1, List<String> keys, List<String> args) {
    return evalsha(sha1, keys.size(), getParams(keys, args));
  }

  public Object evalsha(String sha1, int keyCount, String... params) {
    checkIsInMulti();
    this.client.evalsha(sha1, keyCount, params);

    return getEvalResult();
  }

  public Boolean scriptExists(String sha1) {
    String[] a = new String[1];
    a[0] = sha1;
    return (Boolean)scriptExists(a).get(0);
  }

  public List<Boolean> scriptExists(String... sha1) {
    this.client.scriptExists(sha1);
    List<Long> result = this.client.getIntegerMultiBulkReply();
    List<Boolean> exists = new ArrayList();

    for (Long value : result) {
      exists.add(Boolean.valueOf(value.longValue() == 1L));
    }
    return exists;
  }

  public String scriptLoad(String script) {
    this.client.scriptLoad(script);
    return this.client.getBulkReply();
  }

  public List<Slowlog> slowlogGet() {
    this.client.slowlogGet();
    return Slowlog.from(this.client.getObjectMultiBulkReply());
  }

  public List<Slowlog> slowlogGet(long entries) {
    this.client.slowlogGet(entries);
    return Slowlog.from(this.client.getObjectMultiBulkReply());
  }

  public Long objectRefcount(String string) {
    this.client.objectRefcount(string);
    return this.client.getIntegerReply();
  }

  public String objectEncoding(String string) {
    this.client.objectEncoding(string);
    return this.client.getBulkReply();
  }

  public Long objectIdletime(String string) {
    this.client.objectIdletime(string);
    return this.client.getIntegerReply();
  }
}

  

时间: 2024-10-12 14:03:54

jedis源码阅读的相关文章

CI框架源码阅读笔记3 全局函数Common.php

从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap引导文件都会最先引入全局函数,以便于之后的处理工作). 打开Common.php中,第一行代码就非常诡异: if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 上一篇(CI框架源码阅读笔记2 一切的入口 index

淘宝数据库OceanBase SQL编译器部分 源码阅读--生成逻辑计划

body, td { font-family: tahoma; font-size: 10pt; } 淘宝数据库OceanBase SQL编译器部分 源码阅读--生成逻辑计划 SQL编译解析三部曲分为:构建语法树,生成逻辑计划,指定物理执行计划.第一步骤,在我的上一篇博客淘宝数据库OceanBase SQL编译器部分 源码阅读--解析SQL语法树里做了介绍,这篇博客主要研究第二步,生成逻辑计划. 一. 什么是逻辑计划?我们已经知道,语法树就是一个树状的结构组织,每个节点代表一种类型的语法含义.如

JDK部分源码阅读与理解

本文为博主原创,允许转载,但请声明原文地址:http://www.coselding.cn/article/2016/05/31/JDK部分源码阅读与理解/ 不喜欢重复造轮子,不喜欢贴各种东西.JDK代码什么的,让整篇文章很乱...JDK源码谁都有,没什么好贴的...如果你没看过JDK源码,建议打开Eclipse边看源码边看这篇文章,看过的可以把这篇文章当成是知识点备忘录... JDK容器类中有大量的空指针.数组越界.状态异常等异常处理,这些不是重点,我们关注的应该是它的一些底层的具体实现,这篇

如何阅读Java源码 阅读java的真实体会

刚才在论坛不经意间,看到有关源码阅读的帖子.回想自己前几年,阅读源码那种兴奋和成就感(1),不禁又有一种激动. 源码阅读,我觉得最核心有三点:技术基础+强烈的求知欲+耐心. 说到技术基础,我打个比方吧,如果你从来没有学过Java,或是任何一门编程语言如C++,一开始去啃<Core Java>,你是很难从中吸收到营养的,特别是<深入Java虚拟机>这类书,别人觉得好,未必适合现在的你. 虽然Tomcat的源码很漂亮,但我绝不建议你一开始就读它.我文中会专门谈到这个,暂时不展开. 强烈

Memcache-Java-Client-Release源码阅读(之七)

一.主要内容 本章节的主要内容是介绍Memcache Client的Native,Old_Compat,New_Compat三个Hash算法的应用及实现. 二.准备工作 1.服务器启动192.168.0.106:11211,192.168.0.106:11212两个服务端实例. 2.示例代码: String[] servers = { "192.168.0.106:11211", "192.168.0.106:11212" }; SockIOPool pool =

源码阅读笔记 - 1 MSVC2015中的std::sort

大约寒假开始的时候我就已经把std::sort的源码阅读完毕并理解其中的做法了,到了寒假结尾,姑且把它写出来 这是我的第一篇源码阅读笔记,以后会发更多的,包括算法和库实现,源码会按照我自己的代码风格格式化,去掉或者展开用于条件编译或者debug检查的宏,依重要程度重新排序函数,但是不会改变命名方式(虽然MSVC的STL命名实在是我不能接受的那种),对于代码块的解释会在代码块前(上面)用注释标明. template<class _RanIt, class _Diff, class _Pr> in

JDK 源码 阅读 - 2 - 设计模式 - 创建型模式

A.创建型模式 抽象工厂(Abstract Factory) javax.xml.parsers.DocumentBuilderFactory DocumentBuilderFactory通过FactoryFinder实例化具体的Factory. 使用例子: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilder

CI源码阅读

CodeIgniter源码分析 http://calixwu.com/2014/11/codeigniter-yuanmafenxi.html CI框架源码阅读笔记 http://www.cnblogs.com/ohmygirl/p/4052686.html

《java.util.concurrent 包源码阅读》13 线程池系列之ThreadPoolExecutor 第三部分

这一部分来说说线程池如何进行状态控制,即线程池的开启和关闭. 先来说说线程池的开启,这部分来看ThreadPoolExecutor构造方法: public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecut