Skip to content

Unix Domain Sockets

Mark Paluch edited this page Jan 21, 2017 · 5 revisions

lettuce supports since version 3.2 Unix Domain Sockets for connecting to Redis.

Example 1. Connecting to Redis using RedisURI
RedisURI redisUri = RedisURI.Builder
                             .socket("/tmp/redis")
                             .withPassword("authentication")
                             .withDatabase(2)
                             .build();

RedisClient client = new RedisClient(redisUri);
Example 2. Connecting to Redis using String RedisURI
RedisURI redisUri = RedisURI.create("redis-socket:///tmp/redis");
RedisClient client = new RedisClient(redisUri);

Unix Domain Sockets are inter-process communication channels on POSIX compliant systems. They allow to exchange data between processes on the same host operating system. When using Redis, which is usually a network service, Unix Domain Sockets are usable only if connecting locally to a single instance. Redis Sentinel and Redis Cluster, maintain tables of remote or local nodes and act therefore as a registry. Unix Domain Sockets are not beneficial with Redis Sentinel and Redis Cluster.

Using RedisClusterClient with Unix Domain Sockets would connect to the local node using a socket and then open TCP connection to all the other hosts. A good example is connecting locally to a standalone or a single cluster node to gain performance.

Limitations

Unix Domain Socket support does not work with the shaded version of lettuce because of two reasons:

  1. netty-transport-native-epoll is not packaged into the shaded jar. So adding the jar to the class path will resolve in different netty base classes (such as io.netty.channel.EventLoopGroup instead of com.lambdaworks.io.netty.channel.EventLoopGroup)

  2. Support for using epoll with shaded netty requires netty 4.1 and all parts of netty to be shaded.

Unix Domain Socket connections are currently limited to Linux x86_64 systems with a minimum netty version of 4.0.26.Final. You can, however, port the native library to your system. The netty guys would appreciate. You can check here whether there is a new platform binary available.

Clone this wiki locally