Implementing Connection Management

1. Pinging Server

CommandReturns
PINGPONG
PING "msg"Echoes message

2. Echoing Messages

CommandDescription
ECHO messageRound-trip test, no server processing

3. Selecting Database

CommandDescription
SELECT indexSwitch logical DB (0–15 default)
ClusterOnly DB 0 allowed

4. Quitting Connection

CommandDescription
QUITClose connection DEPRECATED 7.2+
Client-side closePreferred — just close the socket

5. Setting Connection Timeout

DirectiveDefault
timeout 00 = never; otherwise idle seconds
tcp-keepalive 300SO_KEEPALIVE interval

6. Configuring TCP Keepalive

DirectiveEffect
tcp-keepalive secondsDetect dead peers and reduce NAT timeouts

7. Managing Max Clients

DirectiveDefault
maxclients 10000Hard cap; check OS ulimit -n

8. Using HELLO for Protocol Negotiation

CommandDescription
HELLO [version [AUTH user pass] [SETNAME name]]Choose RESP2/RESP3 + auth in one round-trip 6.0+

9. Using RESP3 Protocol

FeatureDetail
Native typesMaps, Sets, Booleans, Doubles, Big numbers
Push messagesOut-of-band frames for tracking/Pub-Sub
NegotiationHELLO 3

10. Implementing Connection Pooling

JedisPoolConfig cfg = new JedisPoolConfig();
cfg.setMaxTotal(64);
cfg.setMaxIdle(16);
cfg.setMinIdle(4);
cfg.setTestOnBorrow(true);
JedisPool pool = new JedisPool(cfg, "redis.host", 6379, 2000, "secret");
try (Jedis jedis = pool.getResource()) {
    jedis.set("k", "v");
}
GuidelineDetail
Pool sizeUsually = concurrent worker threads
ValidatetestOnBorrow for long-lived pools