Unix domain sockets
Connect to a Redis unixsocket listener instead of TCP when Redis runs on the same host, or in a container that shares its socket directory with your application.
await using var redis = await RespireClient.ConnectAsync("unix:///run/redis/redis.sock?db=2");
// Equivalent endpoint with structured options:
var options = new RespireOptions
{
Endpoints = [RespireEndpoint.UnixSocket("/run/redis/redis.sock")],
Database = 2,
};
Connection strings
URI form
unix:///path and redis+unix:///path are both accepted.
- The URI path is the socket path. Select a database with the
dbquery parameter. Other URI query options work as forredis://. - Paths are percent-decoded. Escape
#,?and spaces in file names. For a socket filename ending in a space, useunix:///run/redis/redis.sock%20. - The URI must have no host, port, user information or fragment. Supply credentials through
RespireOptions.UsernameandRespireOptions.Password, a credential provider, or the StackExchange.Redis form below.
StackExchange.Redis form
Prefix the path with !, then add comma-separated options:
!/run/redis/redis.sock,user=app,password=secret,defaultDatabase=2
Comma-separated connection strings trim whitespace around each entry. Use the URI form to preserve a trailing space in the socket filename.
This form treats every comma as a separator, so socket filenames containing commas require a Unix socket URI or structured options. For the socket /tmp/redis,blue.sock, use %2C for the comma and db=2 to select database 2.
unix:///tmp/redis%2Cblue.sock?db=2
Endpoint factory
RespireEndpoint.UnixSocket(path) accepts absolute paths, and relative paths resolved against the current directory at call time. It rejects the root path and paths containing a NUL byte, so Linux abstract socket names are not supported.
Endpoint representation
RespireEndpoint.Hostholds the socket path andPortis0.IsUnixSocketidentifies a socket endpoint, including in connection events.ToString()returns the!pathform. Passing that string toRespireEndpoint.Parsepreserves the full socket path, including trailing spaces.- Public
RespireEndpointequality (including default dictionary and set lookups) uses ordinal, case-sensitive comparison forHost, whether it holds a TCP host name or a Unix socket path.Portmust also match. - For read routing with explicitly configured replicas, Respire matches TCP host names case-insensitively and Unix socket paths case-sensitively.
- Credential providers receive only a cancellation token, not the endpoint.
Behavior
- Command, blocking-pool, pub/sub, cache-tracking and reconnect connections all use the socket.
- RESP2 and RESP3 negotiation and authentication work as over TCP.
- TCP no-delay and keepalive options are not applied.
- Redis Unix sockets do not use TLS:
UseTls = truewith a socket endpoint throwsRespireConfigurationException. Protect the socket with filesystem permissions and Redis ACLs.
Supported topologies
- Standalone primaries and explicitly configured replica endpoints can use sockets.
- Cluster and Sentinel discovery advertise TCP addresses, so combining either with socket endpoints throws
RespireConfigurationExceptionbefore any I/O. - Maintenance notifications are off on socket connections.
MaintenanceNotifications = Enabledwith a socket endpoint throwsRespireConfigurationException, because handoffs target TCP endpoints.
Platform support
The operating system must support UnixDomainSocketEndPoint. Docker Desktop's cross-OS bind mounts do not carry Unix sockets from a Linux container to a Windows host, so sharing a socket that way works only on Linux hosts.