Implementing Connection Management
1. Pinging Server
| Command | Returns |
|---|---|
PING | PONG |
PING "msg" | Echoes message |
2. Echoing Messages
| Command | Description |
|---|---|
ECHO message | Round-trip test, no server processing |
3. Selecting Database
| Command | Description |
|---|---|
SELECT index | Switch logical DB (0–15 default) |
| Cluster | Only DB 0 allowed |
4. Quitting Connection
| Command | Description |
|---|---|
QUIT | Close connection DEPRECATED 7.2+ |
| Client-side close | Preferred — just close the socket |
5. Setting Connection Timeout
| Directive | Default |
|---|---|
timeout 0 | 0 = never; otherwise idle seconds |
tcp-keepalive 300 | SO_KEEPALIVE interval |
6. Configuring TCP Keepalive
| Directive | Effect |
|---|---|
tcp-keepalive seconds | Detect dead peers and reduce NAT timeouts |
7. Managing Max Clients
| Directive | Default |
|---|---|
maxclients 10000 | Hard cap; check OS ulimit -n |
8. Using HELLO for Protocol Negotiation
| Command | Description |
|---|---|
HELLO [version [AUTH user pass] [SETNAME name]] | Choose RESP2/RESP3 + auth in one round-trip 6.0+ |
9. Using RESP3 Protocol
| Feature | Detail |
|---|---|
| Native types | Maps, Sets, Booleans, Doubles, Big numbers |
| Push messages | Out-of-band frames for tracking/Pub-Sub |
| Negotiation | HELLO 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");
}
| Guideline | Detail |
|---|---|
| Pool size | Usually = concurrent worker threads |
| Validate | testOnBorrow for long-lived pools |