← Files RedisARCHIVED FILE
skills/redis-connections/references/pipelining.md
1.08 KB · Oct 3, 2026 · 06:20 UTC
# Use Pipelining for Bulk Operations
Batch multiple commands into a single round trip to reduce network latency.
**Correct:** Use pipeline for multiple commands.
**Python** (redis-py):
```python
# Good: Single round trip for multiple commands
pipe = redis.pipeline()
for user_id in user_ids:
pipe.get(f"user:{user_id}")
results = pipe.execute()
```
**Java** (Jedis):
```java
import redis.clients.jedis.Pipeline;
// Good: Buffer commands and send as single batch
Pipeline pipe = (Pipeline) jedis.pipelined();
pipe.set("person:1:name", "Alex");
pipe.set("person:1:rank", "Captain");
pipe.set("person:1:serial", "AB1234");
pipe.sync();
```
**Incorrect:** Sequential commands in a loop.
**Python** (redis-py):
```python
# Bad: N round trips
results = []
for user_id in user_ids:
results.append(redis.get(f"user:{user_id}"))
```
**Java** (Jedis):
```java
// Bad: 3 separate round trips
jedis.set("person:1:name", "Alex");
jedis.set("person:1:rank", "Captain");
jedis.set("person:1:serial", "AB1234");
```
Reference: [Redis Pipelining](https://redis.io/docs/latest/develop/use/pipelining/)
SHA-256: 3d248ffc53bea0b7841f01f204450006f0deab6527e2390236ee15e024428b7a