Пример #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
 public String shutdown() {
   client.shutdown();
   String status = null;
   try {
     status = client.getStatusCodeReply();
   } catch (JedisException ex) {
     status = null;
   }
   return status;
 }
Пример #3
0
  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
  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
 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
 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
 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
 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
 public void sync() {
   client.sync();
 }
Пример #12
0
 public String flushDB() {
   checkIsInMulti();
   client.flushDB();
   return client.getStatusCodeReply();
 }
Пример #13
0
 public Integer strlen(String key) {
   client.strlen(key);
   return client.getIntegerReply();
 }
Пример #14
0
 public String configSet(String parameter, String value) {
   client.configSet(parameter, value);
   return client.getStatusCodeReply();
 }
Пример #15
0
 public boolean isConnected() {
   return client.isConnected();
 }
Пример #16
0
 public String bgrewriteaof() {
   client.bgrewriteaof();
   return client.getStatusCodeReply();
 }
Пример #17
0
 public List<String> configGet(String pattern) {
   client.configGet(pattern);
   return client.getMultiBulkReply();
 }
Пример #18
0
 public String randomKey() {
   checkIsInMulti();
   client.randomKey();
   return client.getBulkReply();
 }
Пример #19
0
 public String debug(DebugParams params) {
   client.debug(params);
   return client.getStatusCodeReply();
 }
Пример #20
0
 public String echo(String string) {
   client.echo(string);
   return client.getBulkReply();
 }
Пример #21
0
 public Integer persist(String key) {
   client.persist(key);
   return client.getIntegerReply();
 }
Пример #22
0
 public Integer lastsave() {
   client.lastsave();
   return client.getIntegerReply();
 }
Пример #23
0
 public Integer rpushx(String key, String string) {
   client.rpushx(key, string);
   return client.getIntegerReply();
 }
Пример #24
0
 public String info() {
   client.info();
   return client.getBulkReply();
 }
Пример #25
0
 public Integer linsert(String key, LIST_POSITION where, String pivot, String value) {
   client.linsert(key, where, pivot, value);
   return client.getIntegerReply();
 }
Пример #26
0
 public void monitor(JedisMonitor jedisMonitor) {
   client.monitor();
   jedisMonitor.proceed(client);
 }
Пример #27
0
 public List<String> keys(String pattern) {
   checkIsInMulti();
   client.keys(pattern);
   return client.getMultiBulkReply();
 }
Пример #28
0
 public String slaveof(String host, int port) {
   client.slaveof(host, port);
   return client.getStatusCodeReply();
 }
Пример #29
0
 public String rename(String oldkey, String newkey) {
   checkIsInMulti();
   client.rename(oldkey, newkey);
   return client.getStatusCodeReply();
 }
Пример #30
0
 public String slaveofNoOne() {
   client.slaveofNoOne();
   return client.getStatusCodeReply();
 }