Add shared redis client package#108
Merged
Merged
Conversation
Introduce redis/ as a shared connection layer so that downstream projects (toolhive, stacklok-llm-gateway) can stop carrying parallel copies of Redis config, client construction and TLS plumbing. Public surface: - Config, SentinelConfig, TLSConfig - NewClient(ctx, *Config) -> goredis.UniversalClient - BuildTLSConfig(*TLSConfig) -> *tls.Config - DefaultDialTimeout / ReadTimeout / WriteTimeout Supports standalone, Redis Cluster, and Sentinel modes through a single factory. Sentinel mode supports asymmetric TLS for master vs sentinel daemons via a per-target dialer. Validation covers connection-mode topology only; caller-specific rules (key prefix conventions, ACL requirements) remain in the caller. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2ae15af to
1c877d8
Compare
JAORMX
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Multiple ToolHive components (session storage, auth server storage in
toolhive; the API key store instacklok-llm-gatewayonce it migrates off valkey-go) need a Redis client with the same connection-mode topology, TLS handling, and timeout defaults. Today thetoolhiverepo carries two parallel implementations (pkg/transport/session/redis_config.goandpkg/authserver/storage/redis.go) that have already drifted: only the auth-server copy supports Redis Cluster and asymmetric Sentinel TLS.This PR introduces a shared
redis/package intoolhive-coreso the next step can be a pure migration that removes those duplicates and pullsstacklok-llm-gatewayonto the same library.What's in the package
Config,SentinelConfig,TLSConfig— unified configuration types.NewClient(ctx, *Config) (goredis.UniversalClient, error)— single factory covering standalone, Redis Cluster, and Sentinel modes; applies timeout defaults, validates connection-mode topology, and Pings before returning.BuildTLSConfig(*TLSConfig) (*tls.Config, error)— exported for callers that need raw TLS.DefaultDialTimeout,DefaultReadTimeout,DefaultWriteTimeout— tunable defaults.Validation is intentionally limited to connection-mode topology. Caller-specific rules (key-prefix conventions, ACL enforcement) remain in the caller — they vary per consumer.
Why now
Without this package the next migration PR has to either change two repos at once or land a near-duplicate in each consumer. Landing the shared layer first means each subsequent consumer migration is small and reviewable in isolation.
Type of change
Test plan
task test— 9 tests, all pass with-racetask linton./redis/...— 0 issuestask license-check— passtask tidy— clean (all modules verified)CLAUDE.md)Notes for reviewers
github.com/redis/go-redis/v9internally aliased asgoredisto avoid collision with the package name. Callers that need to referencegoredis.UniversalClientshould alias similarly.Config.Addr. This matches the existingtoolhiveauth-server implementation. If multi-seed bootstrap becomes a requirement later,Addrcan be promoted toAddrs []stringadditively.NewClientcopies the caller'sConfigbefore applying defaults, so a single*Configcan safely be reused across constructors without surprise mutation.github.com/redis/go-redis/v9 v9.18.0(direct),github.com/alicebob/miniredis/v2 v2.37.0(test). The indirect additions (go-rendezvous,gopher-lua,go.uber.org/atomic) are transitive.toolhive'spkg/transport/sessionandpkg/authserver/storageonto this package (and, separately,stacklok-llm-gatewayonce it switches from valkey-go to go-redis).🤖 Generated with Claude Code