Skip to content

Commit 1787d31

Browse files
Avoid using QUIT command (#3377)
Backport of #3353 --------- Please refer to: redis/redis#11420 This PR cancels calling the quit command when the Jedis internal link is abnormal, and deprecate the user interface `Jedis.quit()`. This optimizes Jedis connection pool performance and fixes: #2105 --------- Conflicts: src/main/java/redis/clients/jedis/Connection.java src/main/java/redis/clients/jedis/ConnectionFactory.java src/main/java/redis/clients/jedis/Jedis.java src/main/java/redis/clients/jedis/Protocol.java * more changes * Modify makeObject() for Jedis 3.x --------- Co-authored-by: bodong.ybd <[email protected]>
1 parent 84b485d commit 1787d31

File tree

8 files changed

+23
-36
lines changed

8 files changed

+23
-36
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public void connect() {
156156
}
157157
}
158158

159+
/**
160+
* Closing the socket will disconnect the server connection.
161+
*/
159162
@Override
160163
public void disconnect() {
161164
db = 0;
@@ -219,6 +222,11 @@ public void getEx(final byte[] key, final GetExParams params) {
219222
sendCommand(GETEX, params.getByteParams(key));
220223
}
221224

225+
/**
226+
* @deprecated The QUIT command is deprecated, see <a href="https://github.com/redis/redis/issues/11420">#11420</a>.
227+
* {@link BinaryClient#disconnect()} can be used instead.
228+
*/
229+
@Deprecated
222230
public void quit() {
223231
db = 0;
224232
sendCommand(QUIT);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ private void initializeFromClientConfig(JedisClientConfig config) {
110110
}
111111
} catch (JedisException je) {
112112
try {
113-
if (isConnected()) {
114-
quit();
115-
}
116113
disconnect();
117114
} catch (RuntimeException e) {
118115
//
@@ -314,6 +311,9 @@ public void connect() {
314311
client.connect();
315312
}
316313

314+
/**
315+
* Closing the socket will disconnect the server connection.
316+
*/
317317
public void disconnect() {
318318
client.disconnect();
319319
}
@@ -467,8 +467,11 @@ public byte[] getEx(final byte[] key, final GetExParams params) {
467467

468468
/**
469469
* Ask the server to silently close the connection.
470+
* @deprecated The QUIT command is deprecated, see <a href="https://github.com/redis/redis/issues/11420">#11420</a>.
471+
* {@link BinaryJedis#disconnect()} can be used instead.
470472
*/
471473
@Override
474+
@Deprecated
472475
public String quit() {
473476
checkIsInMultiOrPipeline();
474477
client.quit();

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@ public BinaryShardedJedis(List<JedisShardInfo> shards, Hashing algo, Pattern key
5858
public void disconnect() {
5959
for (Jedis jedis : getAllShards()) {
6060
if (jedis.isConnected()) {
61-
try {
62-
// need a proper test, probably with mock
63-
if (!jedis.isBroken()) {
64-
jedis.quit();
65-
}
66-
} catch (JedisConnectionException e) {
67-
// ignore the exception node, so that all other normal nodes can release all connections.
68-
logger.warn("Error while QUIT", e);
69-
}
7061
try {
7162
jedis.disconnect();
7263
} catch (JedisConnectionException e) {
7364
// ignore the exception node, so that all other normal nodes can release all connections.
74-
logger.warn("Error while disconnect", e);
65+
logger.debug("Error while disconnect", e);
7566
}
7667
}
7768
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ public void close() {
246246
disconnect();
247247
}
248248

249+
/**
250+
* Close the socket and disconnect the server.
251+
*/
249252
public void disconnect() {
250253
if (isConnected()) {
251254
try {

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,6 @@ public void activateObject(PooledObject<Jedis> pooledJedis) throws Exception {
154154
public void destroyObject(PooledObject<Jedis> pooledJedis) throws Exception {
155155
final BinaryJedis jedis = pooledJedis.getObject();
156156
if (jedis.isConnected()) {
157-
try {
158-
// need a proper test, probably with mock
159-
if (!jedis.isBroken()) {
160-
jedis.quit();
161-
}
162-
} catch (RuntimeException e) {
163-
logger.debug("Error while QUIT", e);
164-
}
165157
try {
166158
jedis.close();
167159
} catch (RuntimeException e) {
@@ -179,11 +171,6 @@ public PooledObject<Jedis> makeObject() throws Exception {
179171
return new DefaultPooledObject<>(jedis);
180172
} catch (JedisException je) {
181173
if (jedis != null) {
182-
try {
183-
jedis.quit();
184-
} catch (RuntimeException e) {
185-
logger.debug("Error while QUIT", e);
186-
}
187174
try {
188175
jedis.close();
189176
} catch (RuntimeException e) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public static final byte[] toByteArray(final double value) {
253253
}
254254

255255
public static enum Command implements ProtocolCommand {
256-
PING, SET, GET, GETDEL, GETEX, QUIT, EXISTS, DEL, UNLINK, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME,
256+
PING, SET, GET, GETDEL, GETEX, @Deprecated QUIT, EXISTS, DEL, UNLINK, TYPE, FLUSHDB, KEYS, RANDOMKEY, RENAME,
257257
RENAMENX, RENAMEX, DBSIZE, EXPIRE, EXPIREAT, TTL, SELECT, MOVE, FLUSHALL, GETSET, MGET, SETNX,
258258
SETEX, MSET, MSETNX, DECRBY, DECR, INCRBY, INCR, APPEND, SUBSTR, HSET, HGET, HSETNX, HMSET,
259259
HMGET, HINCRBY, HEXISTS, HDEL, HLEN, HKEYS, HVALS, HGETALL, HRANDFIELD, RPUSH, LPUSH, LLEN, LRANGE, LTRIM,

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,10 @@ public void destroyObject(PooledObject<ShardedJedis> pooledShardedJedis) throws
8787
final ShardedJedis shardedJedis = pooledShardedJedis.getObject();
8888
for (Jedis jedis : shardedJedis.getAllShards()) {
8989
if (jedis.isConnected()) {
90-
try {
91-
// need a proper test, probably with mock
92-
if (!jedis.isBroken()) {
93-
jedis.quit();
94-
}
95-
} catch (RuntimeException e) {
96-
logger.warn("Error while QUIT", e);
97-
}
9890
try {
9991
jedis.disconnect();
10092
} catch (RuntimeException e) {
101-
logger.warn("Error while disconnect", e);
93+
logger.debug("Error while disconnect", e);
10294
}
10395
}
10496
}

src/main/java/redis/clients/jedis/commands/BasicCommands.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public interface BasicCommands {
1717
* Ask the server to close the connection. The connection is closed as soon as all pending replies
1818
* have been written to the client.
1919
* @return OK
20+
* @deprecated The QUIT command is deprecated, see <a href="https://github.com/redis/redis/issues/11420">#11420</a>.
21+
* If available, {@code disconnect()} method in the concerned class can be used instead.
2022
*/
23+
@Deprecated
2124
String quit();
2225

2326
/**

0 commit comments

Comments
 (0)