Ready to be merged back to master ...
Last buggy U tests fixed.
This commit is contained in:
@@ -1,15 +1,19 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.toByteArray;
|
||||||
|
import static redis.clients.jedis.Protocol.Command.*;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.LIMIT;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.NO;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.ONE;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.STORE;
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import redis.clients.jedis.Protocol.Command;
|
import redis.clients.jedis.Protocol.Command;
|
||||||
import redis.clients.jedis.Protocol.Keyword;
|
import redis.clients.jedis.Protocol.Keyword;
|
||||||
import static redis.clients.jedis.Protocol.toByteArray;
|
|
||||||
|
|
||||||
import static redis.clients.jedis.Protocol.Command.*;
|
|
||||||
import static redis.clients.jedis.Protocol.Keyword.*;
|
|
||||||
public class BinaryClient extends Connection {
|
public class BinaryClient extends Connection {
|
||||||
public enum LIST_POSITION {
|
public enum LIST_POSITION {
|
||||||
BEFORE, AFTER;
|
BEFORE, AFTER;
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package redis.clients.jedis;
|
package redis.clients.jedis;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static redis.clients.jedis.Protocol.Keyword.*;
|
||||||
|
|
||||||
public abstract class JedisPubSub {
|
public abstract class JedisPubSub {
|
||||||
private int subscribedChannels = 0;
|
private int subscribedChannels = 0;
|
||||||
private Client client;
|
private Client client;
|
||||||
@@ -62,26 +65,78 @@ public abstract class JedisPubSub {
|
|||||||
private void process(Client client) {
|
private void process(Client client) {
|
||||||
do {
|
do {
|
||||||
List<Object> reply = client.getObjectMultiBulkReply();
|
List<Object> reply = client.getObjectMultiBulkReply();
|
||||||
if (reply.get(0).equals("subscribe")) {
|
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 = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onSubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bchannel = (byte[]) reply.get(1);
|
||||||
} else if (reply.get(0).equals("unsubscribe")) {
|
final String strchannel =
|
||||||
|
(bchannel == null) ?
|
||||||
|
null :
|
||||||
|
new String(bchannel, Protocol.UTF8);
|
||||||
|
onSubscribe(strchannel, subscribedChannels);
|
||||||
|
} else if (Arrays.equals(UNSUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onUnsubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bchannel = (byte[]) reply.get(1);
|
||||||
} else if (reply.get(0).equals("message")) {
|
final String strchannel =
|
||||||
onMessage((String) reply.get(1), (String) reply.get(2));
|
(bchannel == null) ?
|
||||||
} else if (reply.get(0).equals("pmessage")) {
|
null :
|
||||||
onPMessage((String) reply.get(1), (String) reply.get(2),
|
new String(bchannel, Protocol.UTF8);
|
||||||
(String) reply.get(3));
|
onUnsubscribe(strchannel, subscribedChannels);
|
||||||
} else if (reply.get(0).equals("psubscribe")) {
|
} 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 :
|
||||||
|
new String(bchannel, Protocol.UTF8);
|
||||||
|
final String strmesg =
|
||||||
|
(bmesg == null) ?
|
||||||
|
null :
|
||||||
|
new String(bmesg, Protocol.UTF8);
|
||||||
|
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 :
|
||||||
|
new String(bpattern, Protocol.UTF8);
|
||||||
|
final String strchannel =
|
||||||
|
(bchannel == null) ?
|
||||||
|
null :
|
||||||
|
new String(bchannel, Protocol.UTF8);
|
||||||
|
final String strmesg =
|
||||||
|
(bmesg == null) ?
|
||||||
|
null :
|
||||||
|
new String(bmesg, Protocol.UTF8);
|
||||||
|
onPMessage(
|
||||||
|
strpattern,
|
||||||
|
strchannel,
|
||||||
|
strmesg);
|
||||||
|
} else if (Arrays.equals(PSUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onPSubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bpattern = (byte[]) reply.get(1);
|
||||||
} else if (reply.get(0).equals("punsubscribe")) {
|
final String strpattern =
|
||||||
|
(bpattern == null) ?
|
||||||
|
null :
|
||||||
|
new String(bpattern, Protocol.UTF8);
|
||||||
|
onPSubscribe(strpattern, subscribedChannels);
|
||||||
|
} else if (Arrays.equals(PUNSUBSCRIBE.raw, resp)) {
|
||||||
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
subscribedChannels = ((Integer) reply.get(2)).intValue();
|
||||||
onPUnsubscribe((String) reply.get(1), subscribedChannels);
|
final byte[] bpattern = (byte[]) reply.get(1);
|
||||||
|
final String strpattern =
|
||||||
|
(bpattern == null) ?
|
||||||
|
null :
|
||||||
|
new String(bpattern, Protocol.UTF8);
|
||||||
|
onPUnsubscribe(strpattern, subscribedChannels);
|
||||||
} else {
|
} else {
|
||||||
throw new JedisException("Unknown message type: "
|
throw new JedisException("Unknown message type: "+ firstObj);
|
||||||
+ reply.get(0));
|
|
||||||
}
|
}
|
||||||
} while (isSubscribed());
|
} while (isSubscribed());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,18 +286,24 @@ public final class Protocol {
|
|||||||
BY,
|
BY,
|
||||||
DESC,
|
DESC,
|
||||||
GET,
|
GET,
|
||||||
|
LIMIT,
|
||||||
|
MESSAGE,
|
||||||
NO,
|
NO,
|
||||||
NOSORT,
|
NOSORT,
|
||||||
|
PMESSAGE,
|
||||||
|
PSUBSCRIBE,
|
||||||
|
PUNSUBSCRIBE,
|
||||||
ONE,
|
ONE,
|
||||||
LIMIT,
|
|
||||||
SET,
|
SET,
|
||||||
STORE,
|
STORE,
|
||||||
|
SUBSCRIBE,
|
||||||
|
UNSUBSCRIBE,
|
||||||
WEIGHTS,
|
WEIGHTS,
|
||||||
WITHSCORES;
|
WITHSCORES;
|
||||||
public final byte[] raw;
|
public final byte[] raw;
|
||||||
|
|
||||||
Keyword() {
|
Keyword() {
|
||||||
raw = this.name().getBytes(UTF8);
|
raw = this.name().toLowerCase().getBytes(UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user