redis-connections

作成者: redis

Redisクライアントと接続に関するガイダンス。コネクションプーリング、多重化、パイプライン、RESP3を使用したクライアントサイドキャッシング、低速コマンド(KEYS、…)の回避をカバー。

npx skills add https://github.com/redis/agent-skills --skill redis-connections

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

redisのその他のスキル

docs-sync
redis
masterブランチの実装と設定を分析し、docs/、README.md、およびパッケージごとのREADMEにあるドキュメントの欠落、誤り、または古い部分を特定します。
redis-query-engine
redis
Redis Query Engine(RQE)のガイダンス:FT.CREATEスキーマ設計、フィールドタイプの選択(TEXT、TAG、NUMERIC、GEO、GEOSHAPE、VECTOR)、DIALECT 2クエリ構文、…
redis-search
redis
Redis Searchのガイダンス:FT.CREATEスキーマ設計、フィールドタイプ選択(TEXT、TAG、NUMERIC、GEO、GEOSHAPE、VECTOR、JSONパス)、DIALECT 2クエリ構文、…
redis-security
redis
Redisのセキュリティガイダンス。認証(requirepassとACLユーザー)、TLS、ACLベースの最小権限アクセス制御、ネットワーク露出の制限などをカバー。
redis-semantic-cache
redis
Redis LangCacheによる、Redis Cloud上でのLLM応答のセマンティックキャッシングのガイダンス — SDKまたはREST APIを介したsearch/setの呼び出し、類似度しきい値の調整、…
redis-vector-search
redis
Redisベクトル検索のガイダンス:HNSWとFLATアルゴリズムの選択、ベクトルインデックス設定(次元数、距離メトリック、データ型)、フィルタリング付きハイブリッド検索…
bump-test-image
redis
共有のDEFAULT_DOCKER_CONFIGとCIマトリックス内のRedis dockerテストイメージ(redislabs/client-libs-test)のデフォルトを更新し、強制プッシュします…
i18n
redis
RedisInsight UI(i18next)の国際化規約。redisinsight/ui/** 配下のユーザー向け文字列を追加・変更する際に使用します。…の編集時…