All skills
redis avatar

/redis-connections

@d3d89fa official
by redisredis/agent-skills163 stars
30

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.

Use this Skill: https://skilld.dev/gh/redis/agent-skills/redis-connections

This session only. Nothing lands on disk.

referencesblocking.md

≈455 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Avoid Slow Commands in Production

Some Redis commands are slow because they scan large datasets. Use incremental alternatives to avoid blocking the server.

Avoid Use Instead
KEYS * SCAN with cursor
SMEMBERS on large sets SSCAN
HGETALL on large hashes HSCAN
LRANGE 0 -1 on large lists Paginate with LRANGE 0 100

Correct: Use SCAN for iteration.

Python (redis-py):

# Good: Non-blocking iteration
cursor = 0
while True:
    cursor, keys = redis.scan(cursor, match="user:*", count=100)
    for key in keys:
        process(key)
    if cursor == 0:
        break

Java (Jedis):

import redis.clients.jedis.ScanIteration;
import redis.clients.jedis.UnifiedJedis;
import java.util.List;

try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) {
    // ScanIteration manages the cursor automatically
    ScanIteration scan = jedis.scanIteration(10, "user:*", "hash");

    while (!scan.isIterationCompleted()) {
        List<String> result = scan.nextBatch().getResult();
        for (String key : result) {
            process(key);
        }
    }
}

Incorrect: Using KEYS in production.

Python (redis-py):

# Bad: Scans all keys, slow on large datasets
keys = redis.keys("user:*")

Java (Jedis):

// Bad: Scans all keys, blocks the server
Set<String> result = jedis.keys("*");

Note: Truly blocking commands (like BLPOP, BRPOP, BLMOVE) that wait indefinitely for data are appropriate for some use cases like job queues, but should be used with timeouts.

# Blocking pop with timeout - appropriate for queue consumers
result = redis.blpop("task_queue", timeout=5)

Reference: Redis SCAN

Source: SKILL.md on GitHub

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides architectural guidance and code examples for Redis connection management, authored by Redis, Inc. It contains no malicious patterns or security risks.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at d3d89fa. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 days ago.

Activeupdated 4 months ago
metadata
{
  "author": "Redis, Inc.",
  "version": "0.1.0"
}
  • redis
  • connection-pooling
  • pipelining
  • resp3
  • client-side-caching
  • timeouts
  • redis-py
  • jedis
  • lettuce
  • performance-tuning

README badge

README badge for redis/agent-skills/redis-connections

Provides patterns for configuring Redis clients to use connection pooling or multiplexing, pipelining bulk commands, avoiding blocking full-keyspace scans, enabling RESP3 client-side caching, and setting appropriate socket timeouts. Covers redis-py, Jedis, Lettuce, go-redis, and NRedisStack.

Generated from the current SKILL.md.

Which Redis clients does this skill cover?
It covers redis-py, Jedis, Lettuce, go-redis, and NRedisStack. The guidance applies to any client but examples are tailored to these libraries.
Does this skill explain how to use blocking commands like BLPOP?
Yes. It notes that blocking commands are fine for queue consumers but must always have a timeout set, and cannot be issued on a multiplexed connection (Lettuce, NRedisStack).
When should I enable client-side caching?
Enable it for read-heavy workloads with infrequent writes, like config, feature flags, or session data on every request. Skip it for write-heavy or frequently changing data, where invalidation traffic outweighs the savings.
What's the difference between connection pooling and multiplexing?
Pooling (redis-py, Jedis, go-redis) keeps multiple persistent connections that are leased per call and blocks if exhausted. Multiplexing (Lettuce, NRedisStack) shares a single connection across all requests and cannot carry blocking commands.
Why should I avoid the KEYS command in production?
KEYS scans the entire keyspace and blocks the server. Use SCAN with a cursor loop instead, or SSCAN/HSCAN for sets and hashes.

Generated from the current SKILL.md. These answers refresh after source changes.