Skip to content

feat(redis): name the cache and queue connections with the node - #233

Merged
cihanalagoz merged 1 commit into
mainfrom
feat/redis-client-name
Aug 21, 2026
Merged

feat(redis): name the cache and queue connections with the node#233
cihanalagoz merged 1 commit into
mainfrom
feat/redis-client-name

Conversation

@cihanalagoz

Copy link
Copy Markdown
Collaborator

Why

Redis connections arrived unnamed, so CLIENT LIST on the server could not say which node or which component owned a connection. That is the first question asked when connections leak or maxclients fills up — and it is a hard requirement from the bank we are onboarding.

What

Both Redis clients now send CLIENT SETNAME:

Site Name
src/lib/core/cache/redisCacheProvider.ts console:<node>:cache
src/lib/core/queue/bullmqQueueProvider.ts console:<node>:queue, console:<node>:queue-sub

No second identity scheme was introduced: the node name comes from the existing getThisNodeName() (NODE_NAME, else hostname-pid), which the queue provider already imported.

Why this is safe on production

  • ioredis sends CLIENT SETNAME in the same awaited batch as the two CLIENT SETINFO commands it already sends on every connect, and wraps it in .catch(noop). A server or proxy that rejects the command still connects.
  • Both providers are opt-in (CACHE_PROVIDER=redis, QUEUE_PROVIDER=bullmq); memory and MongoDB paths are untouched.
  • No key, TTL or payload changed — only connection metadata. The name is re-sent on every reconnect, so it survives a failover.

Verification

  • tsc --noEmit: no new errors (the three pre-existing agentService.ts trace-type errors are unrelated and untouched)
  • src/__tests__/unit/cache-provider.test.ts passing
  • After deploy: redis-cli client list | grep -o 'name=[^ ]*' | sort | uniq -c

Redis connections arrived unnamed, so CLIENT LIST on the server could not tell
which node or which component owned a connection — the first question asked
when connections leak or maxclients fills up.

Both clients now send CLIENT SETNAME as `console:<node>:<role>`, reusing the
cluster identity from getThisNodeName() rather than deriving a second one.

Behaviour is unchanged: ioredis sends SETNAME in the same awaited batch as the
CLIENT SETINFO commands it already sends, and swallows a failure, so a server
that rejects the command still connects.
@cihanalagoz
cihanalagoz merged commit 092b0bc into main Aug 21, 2026
1 check failed
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