You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DATAREDIS-682 - Connect to Redis using unix domain sockets.
We now support Redis connections using OS-native transports through unix domain sockets when using the Lettuce driver. Domain sockets do not require a roundtrip through the networking layer but directly use native epoll or kqueue interfaces.
LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisSocketConfiguration("/var/run/redis.sock"));
Unix domain socket support requires netty's native epoll/kqueue dependencies matching the runtime environment:
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<classifier>linux-x86_64</classifier>
<version>${netty}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<classifier>osx-x86_64</classifier>
<version>${netty}</version>
</dependency>
Original Pull Request: #286
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference/redis.adoc
+50-36Lines changed: 50 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,63 +39,77 @@ NOTE: Depending on the underlying configuration, the factory can return a new co
39
39
40
40
The easiest way to work with a `RedisConnectionFactory` is to configure the appropriate connector through the IoC container and inject it into the using class.
41
41
42
-
IMPORTANT: Unfortunately, currently, not all connectors support all Redis features. When invoking a method on the Connection API that is unsupported by the underlying library, an `UnsupportedOperationException` is thrown.
43
-
This situation is likely to be fixed in the future, as the various connectors mature.
42
+
IMPORTANT: Unfortunately, currently, not all connectors support all Redis features. When invoking a method on the Connection API that is unsupported by the underlying library, an `UnsupportedOperationException` is thrown.
44
43
45
-
[[redis:connectors:jedis]]
46
-
=== Configuring Jedis connector
44
+
[[redis:connectors:lettuce]]
45
+
=== Configuring Lettuce connector
47
46
48
-
http://github.com/xetorthio/jedis[Jedis] is one of the connectors supported by the Spring Data Redis module through the `org.springframework.data.redis.connection.jedis` package. In its simplest form, the Jedis configuration looks as follow:
47
+
https://github.com/lettuce-io/lettuce-core[Lettuce] is a http://netty.io/[netty]-based open-source connector supported by Spring Data Redis through the `org.springframework.data.redis.connection.lettuce` package.
public LettuceConnectionFactory redisConnectionFactory() {
59
56
60
-
</beans>
57
+
return new LettuceConnectionFactory(new RedisStandaloneConfiguration("server", 6379));
58
+
}
59
+
}
61
60
----
62
61
63
-
For production use however, one might want to tweak the settings such as the host or password:
62
+
There are also a few Lettuce-specific connection parameters that can be tweaked. By default, all `LettuceConnection` s created by the `LettuceConnectionFactory` share the same thread-safe native connection for all non-blocking and non-transactional operations. Set `shareNativeConnection` to false to use a dedicated connection each time. `LettuceConnectionFactory` can also be configured with a `LettucePool` to use for pooling blocking and transactional connections, or all connections if `shareNativeConnection` is set to false.
64
63
65
-
[source,xml]
64
+
Lettuce integrates with netty's http://netty.io/wiki/native-transports.html[native transports] allowing to use unix domain sockets to communicate with Redis. Make sure to include the appropriate native transport dependencies that match your runtime environment.
public LettuceConnectionFactory redisConnectionFactory() {
74
73
75
-
</beans>
74
+
return new LettuceConnectionFactory(new RedisSocketConfiguration("/var/run/redis.sock"));
75
+
}
76
+
}
76
77
----
77
78
78
-
[[redis:connectors:lettuce]]
79
-
=== Configuring Lettuce connector
79
+
NOTE: Netty currently supports epoll (Linux) and kqueue (BSD/macOS) interfaces for OS-native transport.
80
80
81
-
https://github.com/mp911de/lettuce[Lettuce] is a http://netty.io/[netty]-based open-source connector supported by Spring Data Redis through the `org.springframework.data.redis.connection.lettuce` package.
81
+
[[redis:connectors:jedis]]
82
+
=== Configuring Jedis connector
82
83
83
-
Its configuration is probably easy to guess:
84
+
http://github.com/xetorthio/jedis[Jedis] is a community-driven connector supported by the Spring Data Redis module through the `org.springframework.data.redis.connection.jedis` package. In its simplest form, the Jedis configuration looks as follow:
public JedisConnectionFactory redisConnectionFactory() {
93
+
return new JedisConnectionFactory();
94
+
}
95
+
}
96
+
----
94
97
95
-
</beans>
98
+
For production use however, one might want to tweak the settings such as the host or password:
99
+
100
+
[source,java]
96
101
----
102
+
@Configuration
103
+
class RedisConfiguration {
97
104
98
-
There are also a few Lettuce-specific connection parameters that can be tweaked. By default, all `LettuceConnection` s created by the `LettuceConnectionFactory` share the same thread-safe native connection for all non-blocking and non-transactional operations. Set `shareNativeConnection` to false to use a dedicated connection each time. `LettuceConnectionFactory` can also be configured with a `LettucePool` to use for pooling blocking and transactional connections, or all connections if `shareNativeConnection` is set to false.
105
+
@Bean
106
+
public JedisConnectionFactory redisConnectionFactory() {
107
+
108
+
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration("server", 6379);
109
+
return new JedisConnectionFactory(config);
110
+
}
111
+
}
112
+
----
99
113
100
114
[[redis:sentinel]]
101
115
== Redis Sentinel Support
@@ -105,7 +119,7 @@ For dealing with high available Redis there is support for http://redis.io/topic
105
119
[source,java]
106
120
----
107
121
/**
108
-
* jedis
122
+
* Jedis
109
123
*/
110
124
@Bean
111
125
public RedisConnectionFactory jedisConnectionFactory() {
0 commit comments