public void unsubscribe() { if (client == null) { throw new JedisConnectionException("JedisPubSub was not subscribed to a Jedis instance."); } client.unsubscribe(); client.flush(); }
public String shutdown() { client.shutdown(); String status = null; try { status = client.getStatusCodeReply(); } catch (JedisException ex) { status = null; } return status; }
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; }
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; }
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; }
public Jedis(ShardInfo shardInfo) { client = new Client(shardInfo.getHost(), shardInfo.getPort()); client.setTimeout(shardInfo.getTimeout()); if (shardInfo.getPassword() != null) { this.auth(shardInfo.getPassword()); } }
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; }
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; }
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()); }
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()); }
public void sync() { client.sync(); }
public String flushDB() { checkIsInMulti(); client.flushDB(); return client.getStatusCodeReply(); }
public Integer strlen(String key) { client.strlen(key); return client.getIntegerReply(); }
public String configSet(String parameter, String value) { client.configSet(parameter, value); return client.getStatusCodeReply(); }
public boolean isConnected() { return client.isConnected(); }
public String bgrewriteaof() { client.bgrewriteaof(); return client.getStatusCodeReply(); }
public List<String> configGet(String pattern) { client.configGet(pattern); return client.getMultiBulkReply(); }
public String randomKey() { checkIsInMulti(); client.randomKey(); return client.getBulkReply(); }
public String debug(DebugParams params) { client.debug(params); return client.getStatusCodeReply(); }
public String echo(String string) { client.echo(string); return client.getBulkReply(); }
public Integer persist(String key) { client.persist(key); return client.getIntegerReply(); }
public Integer lastsave() { client.lastsave(); return client.getIntegerReply(); }
public Integer rpushx(String key, String string) { client.rpushx(key, string); return client.getIntegerReply(); }
public String info() { client.info(); return client.getBulkReply(); }
public Integer linsert(String key, LIST_POSITION where, String pivot, String value) { client.linsert(key, where, pivot, value); return client.getIntegerReply(); }
public void monitor(JedisMonitor jedisMonitor) { client.monitor(); jedisMonitor.proceed(client); }
public List<String> keys(String pattern) { checkIsInMulti(); client.keys(pattern); return client.getMultiBulkReply(); }
public String slaveof(String host, int port) { client.slaveof(host, port); return client.getStatusCodeReply(); }
public String rename(String oldkey, String newkey) { checkIsInMulti(); client.rename(oldkey, newkey); return client.getStatusCodeReply(); }
public String slaveofNoOne() { client.slaveofNoOne(); return client.getStatusCodeReply(); }