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.

referencespooling.md

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

Use Connection Pooling or Multiplexing

Reuse connections via a pool or multiplexing instead of creating new connections per request.

Correct: Use a connection pool.

Python (redis-py):

import redis

# Good: Connection pool - reuses existing connections
pool = redis.ConnectionPool(host='localhost', port=6379, max_connections=50)
r = redis.Redis(connection_pool=pool)

Java (Jedis):

import redis.clients.jedis.JedisPooled;

// JedisPooled manages a connection pool internally
try (JedisPooled jedis = new JedisPooled("redis://localhost:6379")) {
    jedis.set("testKey", "testValue");
}

Correct: Use multiplexing (Lettuce, NRedisStack).

// Lettuce uses multiplexing by default - single connection handles all traffic
RedisClient client = RedisClient.create("redis://localhost:6379");
StatefulRedisConnection<String, String> connection = client.connect();

// All commands share the single connection efficiently
connection.sync().set("key", "value");

Incorrect: Creating new connections per request.

Python (redis-py):

# Bad: New connection every time
def get_user(user_id):
    r = redis.Redis(host='localhost', port=6379)  # Don't do this
    return r.get(f"user:{user_id}")

Java (Jedis):

// Bad: Creating new client per request
public String getUser(String userId) {
    try (UnifiedJedis jedis = new UnifiedJedis("redis://localhost:6379")) {
        return jedis.get("user:" + userId);  // Don't do this
    }
}

Pooling vs Multiplexing:

  • Pooling: Multiple connections shared across requests (redis-py, Jedis, go-redis)
  • Multiplexing: Single connection handles all traffic (NRedisStack, Lettuce)
  • Multiplexing cannot support blocking commands (BLPOP, etc.) as they would stall all callers

Reference: Connection Pools and Multiplexing

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 2 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.