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. - 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
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.- Socket paths compare case-sensitively; DNS host names compare case-insensitively.
- 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.