Skip to content

feat: require caller-owned Redis clients - #67

Merged
lan17 merged 1 commit into
mainfrom
agent/require-caller-owned-redis-client
Jul 18, 2026
Merged

lan17 merged 1 commit into
mainfrom
agent/require-caller-owned-redis-client

Conversation

@lan17

@lan17 lan17 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

This PR makes Redis connection ownership explicit and removes DialCache's lazy client factory.

Applications now create and connect a Redis client, adapt it to DialCacheRedisClient, and pass it through redis.client. DialCache borrows that client for cache operations but never creates, connects, drains, disposes, or closes it.

Ownership contract

  • The application owns the underlying Redis/Valkey client lifecycle.
  • During shutdown, the application stops new DialCache-backed work and awaits all cached-function and invalidateRemote() promises, including fallbacks that may still enqueue a Redis write.
  • The node-redis adapter owns no resources; the application closes node-redis after draining.
  • The GLIDE adapter owns its five Script handles only; the application disposes the adapter after draining, then closes the GLIDE client.
  • DialCache deliberately does not gain a close() or lifecycle subsystem.

Public API and migration

  • RedisConfig.client is now required.
  • RedisConfig.createClient is removed.
  • The root-exported RedisClientFactory type is removed.
  • Untyped callers using the legacy createClient property receive an explicit migration error.

Migration is straightforward: move the old factory body into application startup, retain the client handle, and pass the connected adapter as redis.client. Direct clients already worked in previous releases, so applications can deploy the migrated construction before upgrading DialCache.

This does not change cache keys, Redis frames, Lua protocols, metrics, hit/miss semantics, or fail-open behavior, so rolling upgrades and rollbacks remain wire-compatible.

Runtime impact

Redis operations now use the semantic client directly. This removes the retained factory promise and per-operation client resolution while leaving read, write, invalidation, and fallback behavior unchanged.

Validation

  • Node 22 full pnpm check: 179 tests, typecheck, coverage, build, declarations, and packed-package smoke
  • Node 22 real-Redis integration suite: 46 tests
  • Node 22 focused Redis/adapter suite: 31 tests
  • Node 20.17 packed ESM/CJS/type consumer test
  • git diff --check
  • Two independent final reviewers returned no findings

Resolves #20

@lan17
lan17 marked this pull request as ready for review July 18, 2026 22:15
@lan17
lan17 merged commit 9360d75 into main Jul 18, 2026
3 checks passed
@lan17
lan17 deleted the agent/require-caller-owned-redis-client branch July 18, 2026 22:16
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.

Require caller-owned Redis clients and remove the lazy factory

1 participant