PluginBench
Skill
Official
Pass
Audit score 90

redis-connections

redis/agent-skills

Configure Redis clients efficiently with pooling, pipelining, and client-side caching.

What is redis-connections?

Guidance for setting up Redis clients (redis-py, Jedis, Lettuce, NRedisStack) to maximize throughput and minimize latency. Covers connection pooling vs. multiplexing, command batching, avoiding blocking operations on shared connections, incremental iteration of large datasets, and timeout tuning.

  • Pool or multiplex connections to avoid per-request TCP overhead
  • Batch commands with pipelining for single round-trip execution
  • Replace full-scan commands (KEYS, SMEMBERS, HGETALL) with incremental variants (SCAN, SSCAN, HSCAN)
  • Enable RESP3 client-side caching for read-heavy, write-rare workloads
  • Set explicit connect and read timeouts to fail fast without breaking healthy traffic

How to install redis-connections

npx skills add https://github.com/redis/agent-skills --skill redis-connections
Claude Code
Cursor
Windsurf
Cline

How to use redis-connections

  1. 1.Choose a pooling strategy: connection pool (redis-py, Jedis, go-redis) or multiplexing (Lettuce, NRedisStack) based on your client library
  2. 2.Set pool size or connection limits to match your application's concurrency
  3. 3.Replace N sequential commands with pipelined batches where results are independent
  4. 4.Audit code for blocking commands (KEYS, SMEMBERS, HGETALL, LRANGE 0 -1) and replace with SCAN variants
  5. 5.Enable RESP3 and client-side caching if your workload is read-heavy with infrequent writes
  6. 6.Set socket_connect_timeout and socket_timeout explicitly; use shorter connect timeouts and longer read timeouts

Use cases

Good for
  • Configuring a new Redis client library for an application
  • Reducing latency in code making many small Redis calls
  • Iterating large keyspaces, sets, hashes, or lists without blocking the server
  • Enabling local caching for frequently-read config, feature flags, or session data
  • Tuning socket timeouts for latency-sensitive or batch workloads
Who it's for
  • Backend engineers configuring Redis clients
  • Performance engineers optimizing Redis throughput and latency
  • Developers building queue consumers or real-time applications
  • Teams migrating to or scaling Redis deployments

redis-connections FAQ

Should I use connection pooling or multiplexing?

Use pooling (redis-py, Jedis, go-redis) if your client supports it and you need to run blocking commands like BLPOP. Use multiplexing (Lettuce, NRedisStack) for simpler, single-connection setups where blocking commands are not needed.

When should I enable client-side caching?

Enable RESP3 client-side caching for data that is read often but written rarely, such as config, feature flags, or session data. Skip it for write-heavy workloads or data that changes constantly, as invalidation traffic will outweigh the savings.

What timeout values should I use?

Set connect timeout shorter than read/write timeout. Use tight timeouts (2–5 seconds) for latency-sensitive paths with retry-on-timeout enabled; use longer timeouts for batch jobs. Tune based on your application's expected operation time and failure model.

Why is KEYS pattern slow and what should I use instead?

KEYS scans the entire keyspace and blocks the server. Use SCAN with a cursor loop instead, which iterates incrementally. Similarly, replace SMEMBERS with SSCAN and HGETALL with HSCAN for large containers.

Can I use blocking commands on a multiplexed connection?

No. Blocking commands like BLPOP and BRPOP cannot be used on multiplexed connections (Lettuce, NRedisStack). Use pooled connections for queue consumers, and always pass a timeout to avoid indefinite blocking.

Full instructions (SKILL.md)

Source of truth, from redis/agent-skills.


name: redis-connections description: Redis client and connection guidance covering connection pooling, multiplexing, pipelining, client-side caching with RESP3, avoiding slow commands (KEYS, SMEMBERS, HGETALL), and tuning socket timeouts. Use when configuring a Redis client (redis-py, Jedis, Lettuce, NRedisStack), batching commands for throughput, eliminating per-request connection creation, iterating large keyspaces with SCAN, enabling client-side caching for read-heavy workloads, or setting connect and read timeouts. license: MIT metadata: author: Redis, Inc. version: "0.1.0"

Redis Connections

Client-side guidance for talking to Redis efficiently: how to share connections, how to batch commands, which commands not to call in production, when to turn on client-side caching, and how to set timeouts that fail fast without breaking healthy traffic.

When to apply

  • Creating or reviewing a Redis client setup (redis-py, Jedis, Lettuce, go-redis, NRedisStack).
  • Making many small Redis calls and wondering where the latency is going.
  • Iterating large keyspaces, sets, hashes, or lists.
  • Enabling client-side caching for hot keys.
  • Tuning connect / read / write timeouts.

1. Pool or multiplex — never one connection per request

The single biggest mistake in Redis client code is opening a new TCP connection for every operation. Always either:

  • Pool — keep N persistent connections that the application leases per call (redis-py ConnectionPool, Jedis JedisPooled, go-redis client).
  • Multiplex — share a single connection across all requests (Lettuce, NRedisStack).
StyleUsed byNote
Poolredis-py, Jedis, go-redisEach lease blocks if pool exhausted; size the pool to your concurrency
MultiplexLettuce, NRedisStackSingle connection; cannot carry blocking commands like BLPOP
# redis-py — connection pool
pool = redis.ConnectionPool(host="localhost", port=6379, max_connections=50)
r = redis.Redis(connection_pool=pool)

See references/pooling.md for Python + Java + Lettuce examples.

2. Pipeline bulk work

For N commands that don't depend on each other's results, send them as a single batch with pipelining. One round-trip instead of N.

pipe = redis.pipeline()
for user_id in user_ids:
    pipe.get(f"user:{user_id}")
results = pipe.execute()

Use non-transactional pipelining for performance, and pipeline(transaction=True) only when you actually need atomicity (see redis-core's transactions guidance).

See references/pipelining.md.

3. Avoid commands that scan everything

Anything that walks the whole keyspace (or a whole large container) blocks the server. Use incremental variants instead.

Don'tUse
KEYS patternSCAN cursor loop
SMEMBERS large_setSSCAN
HGETALL large_hashHSCAN
LRANGE 0 -1 on a huge listPaginate (LRANGE 0 100)
cursor = 0
while True:
    cursor, keys = redis.scan(cursor, match="user:*", count=100)
    for key in keys:
        process(key)
    if cursor == 0:
        break

Blocking commands (BLPOP, BRPOP, BLMOVE) are different — they intentionally wait for data and are fine for queue consumers, but always pass a timeout, and don't issue them on a multiplexed connection (Lettuce, NRedisStack).

See references/blocking.md.

4. Client-side caching for hot keys

For data that's read often and written rarely (config, feature flags, sessions on every request), enable RESP3 client-side caching. The client keeps a local copy and the server invalidates it on writes — saving the round trip for hot reads.

client = redis.Redis(
    host="localhost",
    port=6379,
    protocol=3,                                    # RESP3 is required
    cache_config=redis.CacheConfig(max_size=1000),
)

Skip it for write-heavy workloads or data that changes constantly — the invalidation traffic overruns the savings.

See references/client-cache.md.

5. Set explicit timeouts

Defaults vary by client and may be too generous. Pick values that match the application's failure model:

r = redis.Redis(
    host="localhost",
    socket_connect_timeout=2.0,   # fail fast on dead nodes
    socket_timeout=5.0,           # tune to expected operation time
    retry_on_timeout=True,
)

Rule of thumb: connect timeout shorter than read/write timeout. Tight timeouts + retry-on-timeout for latency-sensitive paths; longer timeouts for batch jobs.

See references/timeouts.md.

References