Files
life-echo/api/.agents/skills/redis-development/rules/conn-timeouts.md
Sully 53e0065e3e refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
2026-05-22 13:44:50 +08:00

1.6 KiB

title, impact, impactDescription, tags, description, alwaysApply
title impact impactDescription tags description alwaysApply
Configure Connection Timeouts MEDIUM Improves connection resilience and failure recovery timeouts, connections, reliability Configure Connection Timeouts true

Configure Connection Timeouts

Configure appropriate timeout values to improve your application's connection resilience. While most Redis clients set default timeouts, choosing well-tuned values based on your application's usage patterns leads to better failure recovery.

Correct: Set timeouts based on your application needs.

r = redis.Redis(
    host='localhost',
    socket_timeout=5.0,         # Read/write timeout - tune based on expected operation time
    socket_connect_timeout=2.0,  # Connection timeout - shorter for fast failure detection
    retry_on_timeout=True        # Automatic retry on timeout
)

Incorrect: Relying solely on defaults without considering your use case.

# Not ideal: Default timeouts may not match your application's needs
r = redis.Redis(host='localhost')

# For example, if your app needs fast failure detection,
# the default timeouts might be too generous

Considerations:

  • Set socket_connect_timeout shorter than socket_timeout for quick connection failure detection
  • For latency-sensitive apps, use tighter timeouts with retry logic
  • For batch operations, allow longer timeouts to complete large operations
  • Consider using health checks alongside timeouts for robust failure handling

Reference: Redis Client Configuration