Skip to content

Commit 8896fea

Browse files
authored
Introduce and extend Config pattern (III/2) (#2368)
* Introduce Config pattern * Handle broken status while JedisConnectionException * polishing catch in connect * resolve errors after rebasing * expand jedis socket config * Extend Config pattern * JedisClientConfig extends JedisSocketConfig * polishing, JedisShardInfo, etc * address change requests * address change requests * correct test * refactor/format * copy config params * Unify JedisSocketConfig into JedisClientConfig * address review * remove anti-logical tests for sharded pool * modify uriWithDBindexShouldUseTimeout test * more logging * review: suggest alternate for deprecated * removed unused imports * clarify deprecation * remove deprecation for method that won't be removed
1 parent def09ea commit 8896fea

34 files changed

+1350
-671
lines changed

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

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public class BinaryClient extends Connection {
4040

4141
private boolean isInMulti;
4242

43-
private String user;
44-
private String password;
43+
@Deprecated private String user;
44+
@Deprecated private String password;
4545

4646
private int db;
4747

@@ -51,6 +51,12 @@ public BinaryClient() {
5151
super();
5252
}
5353

54+
/**
55+
* @param host
56+
* @deprecated This constructor will be removed in future. It can be replaced with
57+
* {@link #BinaryClient(java.lang.String, int)} with the host and {@link Protocol#DEFAULT_PORT}.
58+
*/
59+
@Deprecated
5460
public BinaryClient(final String host) {
5561
super(host);
5662
}
@@ -59,16 +65,30 @@ public BinaryClient(final String host, final int port) {
5965
super(host, port);
6066
}
6167

68+
/**
69+
* @deprecated This constructor will be removed in future. Use
70+
* {@link #BinaryClient(redis.clients.jedis.HostAndPort, redis.clients.jedis.JedisClientConfig)}.
71+
*/
72+
@Deprecated
6273
public BinaryClient(final String host, final int port, final boolean ssl) {
6374
super(host, port, ssl);
6475
}
6576

77+
/**
78+
* @deprecated This constructor will be removed in future. Use
79+
* {@link #BinaryClient(redis.clients.jedis.HostAndPort, redis.clients.jedis.JedisClientConfig)}.
80+
*/
81+
@Deprecated
6682
public BinaryClient(final String host, final int port, final boolean ssl,
6783
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
6884
final HostnameVerifier hostnameVerifier) {
6985
super(host, port, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
7086
}
7187

88+
public BinaryClient(final HostAndPort hostPort, final JedisClientConfig clientConfig) {
89+
super(hostPort, clientConfig);
90+
}
91+
7292
public BinaryClient(final JedisSocketFactory jedisSocketFactory) {
7393
super(jedisSocketFactory);
7494
}
@@ -81,31 +101,39 @@ public boolean isInWatch() {
81101
return isInWatch;
82102
}
83103

84-
private byte[][] joinParameters(byte[] first, byte[][] rest) {
85-
byte[][] result = new byte[rest.length + 1][];
86-
result[0] = first;
87-
System.arraycopy(rest, 0, result, 1, rest.length);
88-
return result;
89-
}
90-
91-
private byte[][] joinParameters(byte[] first, byte[] second, byte[][] rest) {
92-
byte[][] result = new byte[rest.length + 2][];
93-
result[0] = first;
94-
result[1] = second;
95-
System.arraycopy(rest, 0, result, 2, rest.length);
96-
return result;
104+
/**
105+
* @param user
106+
* @deprecated This method will be removed in future. Because this class will be restricted from
107+
* holding any user data.
108+
*/
109+
@Deprecated
110+
public void setUser(final String user) {
111+
this.user = user;
97112
}
98113

99-
public void setUser(final String user) { this.user = user; }
100-
114+
/**
115+
* @param password
116+
* @deprecated This method will be removed in future. Because this class will be restricted from
117+
* holding any user data.
118+
*/
119+
@Deprecated
101120
public void setPassword(final String password) {
102121
this.password = password;
103122
}
104123

124+
125+
/**
126+
* This method should be called only after a successful SELECT command.
127+
* @param db
128+
*/
105129
public void setDb(int db) {
106130
this.db = db;
107131
}
108132

133+
public int getDB() {
134+
return db;
135+
}
136+
109137
@Override
110138
public void connect() {
111139
if (!isConnected()) {
@@ -124,6 +152,25 @@ public void connect() {
124152
}
125153
}
126154

155+
@Override
156+
public void disconnect() {
157+
db = 0;
158+
super.disconnect();
159+
}
160+
161+
@Override
162+
public void close() {
163+
db = 0;
164+
super.close();
165+
}
166+
167+
public void resetState() {
168+
if (isInWatch()) {
169+
unwatch();
170+
getStatusCodeReply();
171+
}
172+
}
173+
127174
public void ping() {
128175
sendCommand(PING);
129176
}
@@ -973,29 +1020,6 @@ public void getrange(final byte[] key, final long startOffset, final long endOff
9731020
sendCommand(GETRANGE, key, toByteArray(startOffset), toByteArray(endOffset));
9741021
}
9751022

976-
public int getDB() {
977-
return db;
978-
}
979-
980-
@Override
981-
public void disconnect() {
982-
db = 0;
983-
super.disconnect();
984-
}
985-
986-
@Override
987-
public void close() {
988-
db = 0;
989-
super.close();
990-
}
991-
992-
public void resetState() {
993-
if (isInWatch()) {
994-
unwatch();
995-
getStatusCodeReply();
996-
}
997-
}
998-
9991023
public void eval(final byte[] script, final byte[] keyCount, final byte[][] params) {
10001024
sendCommand(EVAL, joinParameters(script, keyCount, params));
10011025
}
@@ -1654,4 +1678,18 @@ public void xinfoConsumers (byte[] key, byte[] group) {
16541678
sendCommand(XINFO,Keyword.CONSUMERS.getRaw(),key,group);
16551679
}
16561680

1681+
private static byte[][] joinParameters(byte[] first, byte[][] rest) {
1682+
byte[][] result = new byte[rest.length + 1][];
1683+
result[0] = first;
1684+
System.arraycopy(rest, 0, result, 1, rest.length);
1685+
return result;
1686+
}
1687+
1688+
private static byte[][] joinParameters(byte[] first, byte[] second, byte[][] rest) {
1689+
byte[][] result = new byte[rest.length + 2][];
1690+
result[0] = first;
1691+
result[1] = second;
1692+
System.arraycopy(rest, 0, result, 2, rest.length);
1693+
return result;
1694+
}
16571695
}

0 commit comments

Comments
 (0)