Skip to content

perf(redis): tune client pool config - #24

Merged
garrettladley merged 1 commit into
mainfrom
gml/tune-redis-client-config
May 28, 2026
Merged

garrettladley merged 1 commit into
mainfrom
gml/tune-redis-client-config

Conversation

@garrettladley

Copy link
Copy Markdown
Owner
  • add first-class KV_REDIS_* settings for redis pool sizing, timeouts, idle lifetime, and identity suppression
  • apply parsed config.KV values when constructing the go-redis client for both http and stdio servers
  • cover redis config defaults, overrides, parse errors, and go-redis option mapping in tests
  • document the new redis tuning environment variables in README.md

@garrettladley
garrettladley enabled auto-merge (squash) May 28, 2026 21:13
@garrettladley
garrettladley merged commit f4ad20b into main May 28, 2026
3 checks passed
@garrettladley
garrettladley deleted the gml/tune-redis-client-config branch May 28, 2026 21:14
@greptile-apps

greptile-apps Bot commented May 28, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds ten KV_REDIS_* environment variables for fine-grained control of the go-redis client pool (size, idle counts, pool timeout), connection timeouts (dial, read, write), idle lifetime, and identity suppression, and wires those parsed values into goredis.Options via a new applyOptions helper after ParseURL.

  • config.KV gains RedisPool, RedisTimeouts, RedisConnMaxIdle, and RedisDisableIdentity; both server entry-points (httpserver, mcpserver) pass the full config.KV struct instead of a bare URL string.
  • applyOptions unconditionally overwrites all timeout and pool fields on the *goredis.Options returned by ParseURL, which silently discards any equivalent query-parameter values the caller may have embedded in KV_REDIS_URL (go-redis supports ?read_timeout=…&pool_size=… etc. in the URL).
  • The default for KV_REDIS_DISABLE_IDENTITY is true, which inverts go-redis's own default of false and disables connection identity for all existing deployments without an explicit opt-in.

Confidence Score: 3/5

The change is mostly mechanical, but applyOptions unconditionally overwrites URL query-param settings and the identity default is inverted — both affect existing deployments silently.

Two behavioral changes affect all existing deployments without any explicit opt-in: URL query parameters for timeouts and pool settings embedded in KV_REDIS_URL are now silently discarded (applyOptions always wins), and connection identity reporting is now disabled by default, reversing go-redis's own default. The first issue is a real regression for anyone who relied on URL-based Redis config tuning.

internal/kv/redis/redis.go — the applyOptions call site and its unconditional field assignments need a guard or documentation clarifying URL query params are not honored.

Important Files Changed

Filename Overview
internal/kv/redis/redis.go Signature of New/NewStore changed from string to config.KV; new applyOptions helper unconditionally overwrites all timeout/pool fields after ParseURL, which silently discards any values already set by URL query parameters.
internal/config/config.go Adds RedisPool, RedisTimeouts, RedisConnMaxIdle, and RedisDisableIdentity fields with env-var parsing; defaults are reasonable except RedisDisableIdentity defaults to true, inverting go-redis's own default.
internal/config/config_test.go Good coverage: adds default checks, override checks, and a parse-error accumulation check for the new Redis config fields.
internal/kv/redis/redis_test.go New white-box test for applyOptions verifies all fields are mapped correctly from config.KV to goredis.Options.
internal/httpserver/server.go One-line call-site update from kvredis.New(cfg.KV.RedisURL) to kvredis.New(cfg.KV); no logic change.
internal/mcpserver/server.go Identical one-line call-site update as httpserver; no logic change.
README.md Documents all ten new KV_REDIS_* environment variables with their example values; accurate and complete.

Sequence Diagram

sequenceDiagram
    participant Env as Environment
    participant Config as config.Read
    participant Redis as kvredis.New
    participant ParseURL as goredis.ParseURL
    participant ApplyOpts as applyOptions
    participant Client as goredis.NewClient

    Env->>Config: "KV_REDIS_URL and KV_REDIS_* vars"
    Config-->>Redis: config.KV struct
    Redis->>ParseURL: cfg.RedisURL
    ParseURL-->>Redis: goredis.Options with Addr, DB, creds, and any URL query params
    Redis->>ApplyOpts: opts and cfg
    Note over ApplyOpts: Overwrites PoolSize, Timeouts,<br/>IdleConns, DisableIdentity<br/>env-var values win over URL params
    ApplyOpts-->>Redis: modified opts
    Redis->>Client: opts
    Client-->>Redis: goredis.Client
Loading

Reviews (1): Last reviewed commit: "perf(redis): tune client pool config" | Re-trigger Greptile

if err != nil {
return nil, err
}
applyOptions(opts, cfg)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 URL query-param options silently overridden

applyOptions unconditionally overwrites every timeout and pool field that goredis.ParseURL may have already set from URL query parameters. go-redis ParseURL explicitly supports parameters such as ?read_timeout=2s&pool_size=10&dial_timeout=3 (see options.go). Any user whose KV_REDIS_URL includes those query params will have them silently discarded and replaced by the env-var defaults after this change — e.g., redis://host:6379/0?read_timeout=5s would have ReadTimeout set to 5s by ParseURL, then immediately overwritten to 750ms by applyOptions. Guard the assignment so URL-derived non-zero values are not replaced by defaults, or document that URL query params are unsupported.

Comment thread internal/config/config.go
Write: p.duration("KV_REDIS_WRITE_TIMEOUT", 750*time.Millisecond),
},
RedisConnMaxIdle: p.duration("KV_REDIS_CONN_MAX_IDLE_TIME", 10*time.Minute),
RedisDisableIdentity: p.boolean("KV_REDIS_DISABLE_IDENTITY", true),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 RedisDisableIdentity defaults to true, changing existing behavior

Before this PR, no DisableIdentity override existed, so go-redis defaulted to false (identity enabled). Setting the default to true silently disables the CLIENT SETNAME / CLIENT INFO handshake on every new connection for all existing deployments that don't set KV_REDIS_DISABLE_IDENTITY. This makes Redis-side connection monitoring invisible by default. Defaulting to false (the go-redis default) preserves backward-compatible behavior; operators who want to suppress identity for performance can opt-in explicitly.

Suggested change
RedisDisableIdentity: p.boolean("KV_REDIS_DISABLE_IDENTITY", true),
RedisDisableIdentity: p.boolean("KV_REDIS_DISABLE_IDENTITY", false),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant