Skip to content

Commit 4a9b82a

Browse files
committed
Merge branch 'cluster-revised' into cluster-support-multi-key-new
Conflicts: src/main/java/redis/clients/jedis/BinaryJedisCluster.java src/main/java/redis/clients/jedis/JedisCluster.java
2 parents 0f76459 + 53e7dc2 commit 4a9b82a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1884
-1126
lines changed

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ pidfile /tmp/sentinel3.pid
116116
logfile /tmp/sentinel3.log
117117
endef
118118

119+
define REDIS_SENTINEL4
120+
port 26382
121+
daemonize yes
122+
sentinel monitor mymaster 127.0.0.1 6381 1
123+
sentinel auth-pass mymaster foobared
124+
sentinel down-after-milliseconds mymaster 2000
125+
sentinel parallel-syncs mymaster 1
126+
sentinel failover-timeout mymaster 120000
127+
pidfile /tmp/sentinel4.pid
128+
logfile /tmp/sentinel4.log
129+
endef
130+
119131
# CLUSTER REDIS NODES
120132
define REDIS_CLUSTER_NODE1_CONF
121133
daemonize yes
@@ -199,6 +211,7 @@ export REDIS7_CONF
199211
export REDIS_SENTINEL1
200212
export REDIS_SENTINEL2
201213
export REDIS_SENTINEL3
214+
export REDIS_SENTINEL4
202215
export REDIS_CLUSTER_NODE1_CONF
203216
export REDIS_CLUSTER_NODE2_CONF
204217
export REDIS_CLUSTER_NODE3_CONF
@@ -219,6 +232,8 @@ start: cleanup
219232
echo "$$REDIS_SENTINEL2" > /tmp/sentinel2.conf && redis-server /tmp/sentinel2.conf --sentinel
220233
@sleep 0.5
221234
echo "$$REDIS_SENTINEL3" > /tmp/sentinel3.conf && redis-server /tmp/sentinel3.conf --sentinel
235+
@sleep 0.5
236+
echo "$$REDIS_SENTINEL4" > /tmp/sentinel4.conf && redis-server /tmp/sentinel4.conf --sentinel
222237
echo "$$REDIS_CLUSTER_NODE1_CONF" | redis-server -
223238
echo "$$REDIS_CLUSTER_NODE2_CONF" | redis-server -
224239
echo "$$REDIS_CLUSTER_NODE3_CONF" | redis-server -
@@ -241,6 +256,7 @@ stop:
241256
kill `cat /tmp/sentinel1.pid`
242257
kill `cat /tmp/sentinel2.pid`
243258
kill `cat /tmp/sentinel3.pid`
259+
kill `cat /tmp/sentinel4.pid`
244260
kill `cat /tmp/redis_cluster_node1.pid` || true
245261
kill `cat /tmp/redis_cluster_node2.pid` || true
246262
kill `cat /tmp/redis_cluster_node3.pid` || true

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Or use it as a maven dependency:
4848
<dependency>
4949
<groupId>redis.clients</groupId>
5050
<artifactId>jedis</artifactId>
51-
<version>2.4.2</version>
51+
<version>2.6.0</version>
5252
<type>jar</type>
5353
<scope>compile</scope>
5454
</dependency>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<packaging>jar</packaging>
1010
<groupId>redis.clients</groupId>
1111
<artifactId>jedis</artifactId>
12-
<version>2.5.2-SNAPSHOT</version>
12+
<version>2.6.1-SNAPSHOT</version>
1313
<name>Jedis</name>
1414
<description>Jedis is a blazingly small and sane Redis java client.</description>
1515
<url>https://github.com/xetorthio/jedis</url>

src/main/java/redis/clients/jedis/BinaryClient.java

Lines changed: 34 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package redis.clients.jedis;
22

3-
import redis.clients.jedis.Protocol.Command;
4-
import redis.clients.jedis.Protocol.Keyword;
5-
import redis.clients.util.SafeEncoder;
3+
import static redis.clients.jedis.Protocol.toByteArray;
4+
import static redis.clients.jedis.Protocol.Command.*;
5+
import static redis.clients.jedis.Protocol.Keyword.ENCODING;
6+
import static redis.clients.jedis.Protocol.Keyword.IDLETIME;
7+
import static redis.clients.jedis.Protocol.Keyword.LEN;
8+
import static redis.clients.jedis.Protocol.Keyword.LIMIT;
9+
import static redis.clients.jedis.Protocol.Keyword.NO;
10+
import static redis.clients.jedis.Protocol.Keyword.ONE;
11+
import static redis.clients.jedis.Protocol.Keyword.REFCOUNT;
12+
import static redis.clients.jedis.Protocol.Keyword.RESET;
13+
import static redis.clients.jedis.Protocol.Keyword.STORE;
14+
import static redis.clients.jedis.Protocol.Keyword.WITHSCORES;
615

716
import java.util.ArrayList;
817
import java.util.List;
918
import java.util.Map;
1019
import java.util.Map.Entry;
1120

12-
import static redis.clients.jedis.Protocol.Command.*;
13-
import static redis.clients.jedis.Protocol.Command.EXISTS;
14-
import static redis.clients.jedis.Protocol.Command.PSUBSCRIBE;
15-
import static redis.clients.jedis.Protocol.Command.PUNSUBSCRIBE;
16-
import static redis.clients.jedis.Protocol.Command.SUBSCRIBE;
17-
import static redis.clients.jedis.Protocol.Command.UNSUBSCRIBE;
18-
import static redis.clients.jedis.Protocol.Keyword.*;
19-
import static redis.clients.jedis.Protocol.toByteArray;
21+
import redis.clients.jedis.Protocol.Command;
22+
import redis.clients.jedis.Protocol.Keyword;
23+
import redis.clients.util.SafeEncoder;
2024

2125
public class BinaryClient extends Connection {
2226
public enum LIST_POSITION {
@@ -827,6 +831,25 @@ public void zinterstore(final byte[] dstkey, final ZParams params,
827831
args.addAll(params.getParams());
828832
sendCommand(ZINTERSTORE, args.toArray(new byte[args.size()][]));
829833
}
834+
835+
public void zlexcount(final byte[] key, final byte[] min, final byte[] max) {
836+
sendCommand(ZLEXCOUNT, key, min, max);
837+
}
838+
839+
public void zrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
840+
sendCommand(ZRANGEBYLEX, key, min, max);
841+
}
842+
843+
public void zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
844+
final int offset, final int count) {
845+
sendCommand(ZRANGEBYLEX, key, min, max, LIMIT.raw,
846+
toByteArray(offset), toByteArray(count));
847+
}
848+
849+
public void zremrangeByLex(byte[] key, byte[] min, byte[] max) {
850+
sendCommand(ZREMRANGEBYLEX, key, min, max);
851+
}
852+
830853

831854
public void save() {
832855
sendCommand(SAVE);
@@ -963,9 +986,6 @@ public void close() {
963986
}
964987

965988
public void resetState() {
966-
if (isInMulti())
967-
discard();
968-
969989
if (isInWatch())
970990
unwatch();
971991
}
@@ -1099,11 +1119,6 @@ public void restore(final byte[] key, final int ttl,
10991119
sendCommand(RESTORE, key, toByteArray(ttl), serializedValue);
11001120
}
11011121

1102-
@Deprecated
1103-
public void pexpire(final byte[] key, final int milliseconds) {
1104-
pexpire(key, (long) milliseconds);
1105-
}
1106-
11071122
public void pexpire(final byte[] key, final long milliseconds) {
11081123
sendCommand(PEXPIRE, key, toByteArray(milliseconds));
11091124
}
@@ -1165,61 +1180,6 @@ public void hincrByFloat(final byte[] key, final byte[] field,
11651180
sendCommand(HINCRBYFLOAT, key, field, toByteArray(increment));
11661181
}
11671182

1168-
@Deprecated
1169-
/**
1170-
* This method is deprecated due to bug (scan cursor should be unsigned long)
1171-
* And will be removed on next major release
1172-
* @see https://github.com/xetorthio/jedis/issues/531
1173-
*/
1174-
public void scan(int cursor, final ScanParams params) {
1175-
final List<byte[]> args = new ArrayList<byte[]>();
1176-
args.add(toByteArray(cursor));
1177-
args.addAll(params.getParams());
1178-
sendCommand(SCAN, args.toArray(new byte[args.size()][]));
1179-
}
1180-
1181-
@Deprecated
1182-
/**
1183-
* This method is deprecated due to bug (scan cursor should be unsigned long)
1184-
* And will be removed on next major release
1185-
* @see https://github.com/xetorthio/jedis/issues/531
1186-
*/
1187-
public void hscan(final byte[] key, int cursor, final ScanParams params) {
1188-
final List<byte[]> args = new ArrayList<byte[]>();
1189-
args.add(key);
1190-
args.add(toByteArray(cursor));
1191-
args.addAll(params.getParams());
1192-
sendCommand(HSCAN, args.toArray(new byte[args.size()][]));
1193-
}
1194-
1195-
@Deprecated
1196-
/**
1197-
* This method is deprecated due to bug (scan cursor should be unsigned long)
1198-
* And will be removed on next major release
1199-
* @see https://github.com/xetorthio/jedis/issues/531
1200-
*/
1201-
public void sscan(final byte[] key, int cursor, final ScanParams params) {
1202-
final List<byte[]> args = new ArrayList<byte[]>();
1203-
args.add(key);
1204-
args.add(toByteArray(cursor));
1205-
args.addAll(params.getParams());
1206-
sendCommand(SSCAN, args.toArray(new byte[args.size()][]));
1207-
}
1208-
1209-
@Deprecated
1210-
/**
1211-
* This method is deprecated due to bug (scan cursor should be unsigned long)
1212-
* And will be removed on next major release
1213-
* @see https://github.com/xetorthio/jedis/issues/531
1214-
*/
1215-
public void zscan(final byte[] key, int cursor, final ScanParams params) {
1216-
final List<byte[]> args = new ArrayList<byte[]>();
1217-
args.add(key);
1218-
args.add(toByteArray(cursor));
1219-
args.addAll(params.getParams());
1220-
sendCommand(ZSCAN, args.toArray(new byte[args.size()][]));
1221-
}
1222-
12231183
public void scan(final byte[] cursor, final ScanParams params) {
12241184
final List<byte[]> args = new ArrayList<byte[]>();
12251185
args.add(cursor);

src/main/java/redis/clients/jedis/BinaryJedis.java

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
import redis.clients.jedis.exceptions.JedisDataException;
1818
import redis.clients.jedis.exceptions.JedisException;
1919
import redis.clients.util.JedisByteHashMap;
20+
import redis.clients.util.JedisURIHelper;
2021
import redis.clients.util.SafeEncoder;
2122

2223
public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
2324
MultiKeyBinaryCommands, AdvancedBinaryJedisCommands,
2425
BinaryScriptingCommands, Closeable {
2526
protected Client client = null;
26-
27+
protected Transaction transaction = null;
28+
protected Pipeline pipeline = null;
29+
2730
public BinaryJedis(final String host) {
2831
URI uri = URI.create(host);
2932
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
30-
client = new Client(uri.getHost(), uri.getPort());
31-
client.auth(uri.getUserInfo().split(":", 2)[1]);
32-
client.getStatusCodeReply();
33-
client.select(Integer.parseInt(uri.getPath().split("/", 2)[1]));
34-
client.getStatusCodeReply();
33+
initializeClientFromURI(uri);
3534
} else {
3635
client = new Client(host);
3736
}
@@ -53,11 +52,28 @@ public BinaryJedis(final JedisShardInfo shardInfo) {
5352
}
5453

5554
public BinaryJedis(URI uri) {
55+
initializeClientFromURI(uri);
56+
}
57+
58+
public BinaryJedis(final URI uri, final int timeout) {
59+
initializeClientFromURI(uri);
60+
client.setTimeout(timeout);
61+
}
62+
63+
private void initializeClientFromURI(URI uri) {
5664
client = new Client(uri.getHost(), uri.getPort());
57-
client.auth(uri.getUserInfo().split(":", 2)[1]);
58-
client.getStatusCodeReply();
59-
client.select(Integer.parseInt(uri.getPath().split("/", 2)[1]));
60-
client.getStatusCodeReply();
65+
66+
String password = JedisURIHelper.getPassword(uri);
67+
if (password != null) {
68+
client.auth(password);
69+
client.getStatusCodeReply();
70+
}
71+
72+
Integer dbIndex = JedisURIHelper.getDBIndex(uri);
73+
if (dbIndex > 0) {
74+
client.select(dbIndex);
75+
client.getStatusCodeReply();
76+
}
6177
}
6278

6379
public String ping() {
@@ -1753,7 +1769,9 @@ public Double zscore(final byte[] key, final byte[] member) {
17531769

17541770
public Transaction multi() {
17551771
client.multi();
1756-
return new Transaction(client);
1772+
client.getOne(); // expected OK
1773+
transaction = new Transaction(client);
1774+
return transaction;
17571775
}
17581776

17591777
@Deprecated
@@ -1767,6 +1785,7 @@ public List<Object> multi(final TransactionBlock jedisTransaction) {
17671785
List<Object> results = null;
17681786
jedisTransaction.setClient(client);
17691787
client.multi();
1788+
client.getOne(); // expected OK
17701789
jedisTransaction.execute();
17711790
results = jedisTransaction.exec();
17721791
return results;
@@ -1789,9 +1808,23 @@ public void disconnect() {
17891808

17901809
public void resetState() {
17911810
if (client.isConnected()) {
1811+
if (transaction != null) {
1812+
transaction.clear();
1813+
}
1814+
1815+
if (pipeline != null) {
1816+
pipeline.clear();
1817+
}
1818+
1819+
if (client.isInWatch()) {
1820+
unwatch();
1821+
}
1822+
17921823
client.resetState();
1793-
client.getAll();
17941824
}
1825+
1826+
transaction = null;
1827+
pipeline = null;
17951828
}
17961829

17971830
public String watch(final byte[]... keys) {
@@ -2207,7 +2240,7 @@ public List<Object> pipelined(final PipelineBlock jedisPipeline) {
22072240
}
22082241

22092242
public Pipeline pipelined() {
2210-
Pipeline pipeline = new Pipeline();
2243+
pipeline = new Pipeline();
22112244
pipeline.setClient(client);
22122245
return pipeline;
22132246
}
@@ -2793,6 +2826,35 @@ public Long zinterstore(final byte[] dstkey, final ZParams params,
27932826
return client.getIntegerReply();
27942827
}
27952828

2829+
@Override
2830+
public Long zlexcount(final byte[] key, final byte[] min, final byte[] max) {
2831+
checkIsInMulti();
2832+
client.zlexcount(key, min, max);
2833+
return client.getIntegerReply();
2834+
}
2835+
2836+
@Override
2837+
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
2838+
checkIsInMulti();
2839+
client.zrangeByLex(key, min, max);
2840+
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
2841+
}
2842+
2843+
@Override
2844+
public Set<byte[]> zrangeByLex(final byte[] key, final byte[] min, final byte[] max,
2845+
final int offset, final int count) {
2846+
checkIsInMulti();
2847+
client.zrangeByLex(key, min, max, offset, count);
2848+
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
2849+
}
2850+
2851+
@Override
2852+
public Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max) {
2853+
checkIsInMulti();
2854+
client.zremrangeByLex(key, min, max);
2855+
return client.getIntegerReply();
2856+
}
2857+
27962858
/**
27972859
* Synchronously save the DB on disk.
27982860
* <p>
@@ -3385,11 +3447,6 @@ public String restore(final byte[] key, final int ttl,
33853447
return client.getStatusCodeReply();
33863448
}
33873449

3388-
@Deprecated
3389-
public Long pexpire(final byte[] key, final int milliseconds) {
3390-
return pexpire(key, (long) milliseconds);
3391-
}
3392-
33933450
public Long pexpire(final byte[] key, final long milliseconds) {
33943451
checkIsInMulti();
33953452
client.pexpire(key, milliseconds);

0 commit comments

Comments
 (0)