# keyval/connect Create a Valkey/Redis (RESP2 + RESP3) client. The client dials lazily on the first `keyval/cmd`, and re-dials after a failed connection, so `connect` itself cannot fail on a dead server. ## Syntax
[keyval/connect "host" port ?opts]
## Parameters - `$host` — non-empty hostname or IP (string) - `$port` — TCP port (number) - `$opts` — optional map: - `:tls` — `true` for TLS (build must have SSL enabled) - `:timeout` — per-command deadline in ms (default 60000; `0` disables) - `:username` / `:password` — AUTH credentials (strings) - `:db` — SELECT database number HELLO 3 is negotiated on connect and AUTH/SELECT are queued behind it; a server that rejects HELLO falls back to RESP2 transparently. ## Examples
def rds [keyval/connect "localhost" 6379]
def tls [keyval/connect "cache.example.com" 6380 %{ :tls true :db 2 }]
## Returns A `keyval_client` native resource, or `%Err{:message}` on bad arguments, allocation failure, or `:tls true` in a build without SSL (`"SSL not enabled (build with -Dssl=true)"`). ## See Also `keyval/cmd`, `keyval/on-message`, `keyval/info`