示例#1
0
 public void unsubscribe() {
   if (client == null) {
     throw new JedisConnectionException("JedisPubSub was not subscribed to a Jedis instance.");
   }
   client.unsubscribe();
   client.flush();
 }
示例#2
0
文件: Jedis.java 项目: jsncpr/jedis
 public String shutdown() {
   client.shutdown();
   String status = null;
   try {
     status = client.getStatusCodeReply();
   } catch (JedisException ex) {
     status = null;
   }
   return status;
 }
示例#3
0
文件: Jedis.java 项目: jsncpr/jedis
  public Map<String, String> hgetAll(String key) {
    checkIsInMulti();
    client.hgetAll(key);
    List<String> flatHash = client.getMultiBulkReply();
    Map<String, String> hash = new HashMap<String, String>();
    Iterator<String> iterator = flatHash.iterator();
    while (iterator.hasNext()) {
      hash.put(iterator.next(), iterator.next());
    }

    return hash;
  }
示例#4
0
文件: Jedis.java 项目: jsncpr/jedis
  public List<String> blpop(int timeout, String... keys) {
    checkIsInMulti();
    List<String> args = new ArrayList<String>();
    for (String arg : keys) {
      args.add(arg);
    }
    args.add(String.valueOf(timeout));

    client.blpop(args.toArray(new String[args.size()]));
    client.setTimeoutInfinite();
    List<String> multiBulkReply = client.getMultiBulkReply();
    client.rollbackTimeout();
    return multiBulkReply;
  }
示例#5
0
文件: Jedis.java 项目: jsncpr/jedis
 public Set<Tuple> zrangeByScoreWithScores(
     String key, double min, double max, int offset, int count) {
   checkIsInMulti();
   client.zrangeByScoreWithScores(key, min, max, offset, count);
   Set<Tuple> set = getTupledSet();
   return set;
 }
示例#6
0
文件: Jedis.java 项目: jsncpr/jedis
 public Jedis(ShardInfo shardInfo) {
   client = new Client(shardInfo.getHost(), shardInfo.getPort());
   client.setTimeout(shardInfo.getTimeout());
   if (shardInfo.getPassword() != null) {
     this.auth(shardInfo.getPassword());
   }
 }
示例#7
0
文件: Jedis.java 项目: jsncpr/jedis
 private Set<Tuple> getTupledSet() {
   checkIsInMulti();
   List<String> membersWithScores = client.getMultiBulkReply();
   Set<Tuple> set = new LinkedHashSet<Tuple>();
   Iterator<String> iterator = membersWithScores.iterator();
   while (iterator.hasNext()) {
     set.add(new Tuple(iterator.next(), Double.valueOf(iterator.next())));
   }
   return set;
 }
示例#8
0
文件: Jedis.java 项目: jsncpr/jedis
 public List<Object> multi(TransactionBlock jedisTransaction) {
   List<Object> results = null;
   try {
     jedisTransaction.setClient(client);
     multi();
     jedisTransaction.execute();
     results = jedisTransaction.exec();
   } catch (Exception ex) {
     client.discard();
   }
   return results;
 }
示例#9
0
 private void process(Client client) {
   do {
     List<Object> reply = client.getObjectMultiBulkReply();
     final Object firstObj = reply.get(0);
     if (!(firstObj instanceof byte[])) {
       throw new JedisException("Unknown message type: " + firstObj);
     }
     final byte[] resp = (byte[]) firstObj;
     if (Arrays.equals(SUBSCRIBE.raw, resp)) {
       subscribedChannels = ((Long) reply.get(2)).intValue();
       final byte[] bchannel = (byte[]) reply.get(1);
       final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
       onSubscribe(strchannel, subscribedChannels);
     } else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
       subscribedChannels = ((Long) reply.get(2)).intValue();
       final byte[] bchannel = (byte[]) reply.get(1);
       final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
       onUnsubscribe(strchannel, subscribedChannels);
     } else if (Arrays.equals(MESSAGE.raw, resp)) {
       final byte[] bchannel = (byte[]) reply.get(1);
       final byte[] bmesg = (byte[]) reply.get(2);
       final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
       final String strmesg = (bmesg == null) ? null : SafeEncoder.encode(bmesg);
       onMessage(strchannel, strmesg);
     } else if (Arrays.equals(PMESSAGE.raw, resp)) {
       final byte[] bpattern = (byte[]) reply.get(1);
       final byte[] bchannel = (byte[]) reply.get(2);
       final byte[] bmesg = (byte[]) reply.get(3);
       final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
       final String strchannel = (bchannel == null) ? null : SafeEncoder.encode(bchannel);
       final String strmesg = (bmesg == null) ? null : SafeEncoder.encode(bmesg);
       onPMessage(strpattern, strchannel, strmesg);
     } else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
       subscribedChannels = ((Long) reply.get(2)).intValue();
       final byte[] bpattern = (byte[]) reply.get(1);
       final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
       onPSubscribe(strpattern, subscribedChannels);
     } else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
       subscribedChannels = ((Long) reply.get(2)).intValue();
       final byte[] bpattern = (byte[]) reply.get(1);
       final String strpattern = (bpattern == null) ? null : SafeEncoder.encode(bpattern);
       onPUnsubscribe(strpattern, subscribedChannels);
     } else {
       throw new JedisException("Unknown message type: " + firstObj);
     }
   } while (isSubscribed());
 }
示例#10
0
 private void process(final Client client) {
   do {
     final List<Object> reply = client.getObjectMultiBulkReply();
     final Object firstObj = reply.get(0);
     if (!(firstObj instanceof byte[])) {
       throw new JedisException("Unknown message type: " + firstObj);
     }
     final byte[] resp = (byte[]) firstObj;
     if (Arrays.equals(Protocol.Keyword.SUBSCRIBE.raw, resp)) {
       this.subscribedChannels = (int) (Object) reply.get(2);
       final byte[] bchannel = reply.get(1);
       this.onSubscribe(bchannel, this.subscribedChannels);
     } else if (Arrays.equals(Protocol.Keyword.UNSUBSCRIBE.raw, resp)) {
       this.subscribedChannels = (int) (Object) reply.get(2);
       final byte[] bchannel = reply.get(1);
       this.onUnsubscribe(bchannel, this.subscribedChannels);
     } else if (Arrays.equals(Protocol.Keyword.MESSAGE.raw, resp)) {
       final byte[] bchannel = reply.get(1);
       final byte[] bmesg = reply.get(2);
       this.onMessage(bchannel, bmesg);
     } else if (Arrays.equals(Protocol.Keyword.PMESSAGE.raw, resp)) {
       final byte[] bpattern = reply.get(1);
       final byte[] bchannel2 = reply.get(2);
       final byte[] bmesg2 = reply.get(3);
       this.onPMessage(bpattern, bchannel2, bmesg2);
     } else if (Arrays.equals(Protocol.Keyword.PSUBSCRIBE.raw, resp)) {
       this.subscribedChannels = (int) (Object) reply.get(2);
       final byte[] bpattern = reply.get(1);
       this.onPSubscribe(bpattern, this.subscribedChannels);
     } else {
       if (!Arrays.equals(Protocol.Keyword.PUNSUBSCRIBE.raw, resp)) {
         throw new JedisException("Unknown message type: " + firstObj);
       }
       this.subscribedChannels = (int) (Object) reply.get(2);
       final byte[] bpattern = reply.get(1);
       this.onPUnsubscribe(bpattern, this.subscribedChannels);
     }
   } while (this.isSubscribed());
 }
示例#11
0
文件: Jedis.java 项目: jsncpr/jedis
 public void sync() {
   client.sync();
 }
示例#12
0
文件: Jedis.java 项目: jsncpr/jedis
 public String flushDB() {
   checkIsInMulti();
   client.flushDB();
   return client.getStatusCodeReply();
 }
示例#13
0
文件: Jedis.java 项目: jsncpr/jedis
 public Integer strlen(String key) {
   client.strlen(key);
   return client.getIntegerReply();
 }
示例#14
0
文件: Jedis.java 项目: jsncpr/jedis
 public String configSet(String parameter, String value) {
   client.configSet(parameter, value);
   return client.getStatusCodeReply();
 }
示例#15
0
文件: Jedis.java 项目: jsncpr/jedis
 public boolean isConnected() {
   return client.isConnected();
 }
示例#16
0
文件: Jedis.java 项目: jsncpr/jedis
 public String bgrewriteaof() {
   client.bgrewriteaof();
   return client.getStatusCodeReply();
 }
示例#17
0
文件: Jedis.java 项目: jsncpr/jedis
 public List<String> configGet(String pattern) {
   client.configGet(pattern);
   return client.getMultiBulkReply();
 }
示例#18
0
文件: Jedis.java 项目: jsncpr/jedis
 public String randomKey() {
   checkIsInMulti();
   client.randomKey();
   return client.getBulkReply();
 }
示例#19
0
文件: Jedis.java 项目: jsncpr/jedis
 public String debug(DebugParams params) {
   client.debug(params);
   return client.getStatusCodeReply();
 }
示例#20
0
文件: Jedis.java 项目: jsncpr/jedis
 public String echo(String string) {
   client.echo(string);
   return client.getBulkReply();
 }
示例#21
0
文件: Jedis.java 项目: jsncpr/jedis
 public Integer persist(String key) {
   client.persist(key);
   return client.getIntegerReply();
 }
示例#22
0
文件: Jedis.java 项目: jsncpr/jedis
 public Integer lastsave() {
   client.lastsave();
   return client.getIntegerReply();
 }
示例#23
0
文件: Jedis.java 项目: jsncpr/jedis
 public Integer rpushx(String key, String string) {
   client.rpushx(key, string);
   return client.getIntegerReply();
 }
示例#24
0
文件: Jedis.java 项目: jsncpr/jedis
 public String info() {
   client.info();
   return client.getBulkReply();
 }
示例#25
0
文件: Jedis.java 项目: jsncpr/jedis
 public Integer linsert(String key, LIST_POSITION where, String pivot, String value) {
   client.linsert(key, where, pivot, value);
   return client.getIntegerReply();
 }
示例#26
0
文件: Jedis.java 项目: jsncpr/jedis
 public void monitor(JedisMonitor jedisMonitor) {
   client.monitor();
   jedisMonitor.proceed(client);
 }
示例#27
0
文件: Jedis.java 项目: jsncpr/jedis
 public List<String> keys(String pattern) {
   checkIsInMulti();
   client.keys(pattern);
   return client.getMultiBulkReply();
 }
示例#28
0
文件: Jedis.java 项目: jsncpr/jedis
 public String slaveof(String host, int port) {
   client.slaveof(host, port);
   return client.getStatusCodeReply();
 }
示例#29
0
文件: Jedis.java 项目: jsncpr/jedis
 public String rename(String oldkey, String newkey) {
   checkIsInMulti();
   client.rename(oldkey, newkey);
   return client.getStatusCodeReply();
 }
示例#30
0
文件: Jedis.java 项目: jsncpr/jedis
 public String slaveofNoOne() {
   client.slaveofNoOne();
   return client.getStatusCodeReply();
 }