Skip to content

Add option to attach an adapter in valkeyAsyncConnectWithOptions()#331

Open
bjosv wants to merge 2 commits into
valkey-io:mainfrom
bjosv:add-adapter-option
Open

Add option to attach an adapter in valkeyAsyncConnectWithOptions()#331
bjosv wants to merge 2 commits into
valkey-io:mainfrom
bjosv:add-adapter-option

Conversation

@bjosv

@bjosv bjosv commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Add attach_fn and attach_data to valkeyOptions, allowing the event-loop adapter to be specified as part of the connection options. When set, valkeyAsyncConnectWithOptions() attaches the adapter internally after the connect is initiated.

This mirrors the existing cluster API pattern (valkeyClusterOptions) and enables future work where the adapter drives non-blocking DNS resolution.

The legacy path (attaching the adapter separately after connect) remains fully supported.

Changes

  • Adds attach_fn / attach_data fields in valkeyOptions
  • For TCP: connect is deferred (VALKEY_CONNECT_DEFERRED) until after context setup, then DNS + connect runs before adapter attach
  • For Unix: connect completes immediately, adapter attached directly

Add attach_fn and attach_data to valkeyOptions, allowing the event-loop
adapter to be specified as part of the connection options. When set,
valkeyAsyncConnectWithOptions() attaches the adapter and registers the
fd with the event loop internally.

For TCP connections, connect is deferred past context initialization to
ensure the context is fully set up before the connect call. The adapter
receives a valid fd and works without modification.

This mirrors the existing cluster API pattern (valkeyClusterOptions) and
enables future work where the adapter drives non-blocking DNS resolution.

The legacy path (attaching the adapter separately after connect) remains
fully supported.

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
@bjosv bjosv requested a review from michael-grunder July 3, 2026 12:00
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>

@michael-grunder michael-grunder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Edit: Deleted comment with s/above/below/ I misread the sentence.

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.

2 participants