springboot2 Redis Lettuce

Lettuce解释:Lettuce is a scalable thread-safe Redis client based on netty and Reactor. Lettuce provides synchronous, asynchronousand reactive APIs to interact with Redis.

Configuring the Lettuce Connector
Lettuce is a Netty-based open-source connector supported by Spring Data Redis through the org.springframework.data.redis.connection.lettuce package. The following example shows how to create a new Lettuce connection factory:
@Configuration
class AppConfig {
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory(new RedisStandaloneConfiguration("server", 6379));
}
}
There are also a few Lettuce-specific connection parameters that can be tweaked. By default, all LettuceConnection instances created by the LettuceConnectionFactory share the same thread-safe native connection for all non-blocking and non-transactional operations. To use a dedicated connection each time, set shareNativeConnection to false. LettuceConnectionFactory can also be configured to use a LettucePool for pooling blocking and transactional connections or all connections if shareNativeConnection is set to false.
是不是可以理解为只有在使用redis事物的时候才有必要配置LettucePool连接池?

The following example shows a more sophisticated configuration, including SSL and timeouts, that uses LettuceClientConfigurationBuilder:
@Bean
public ReactiveRedisConnectionFactory lettuceConnectionFactory() {
LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder()
.useSsl().and()
.commandTimeout(Duration.ofSeconds(2))
.shutdownTimeout(Duration.ZERO)
.build();
return new LettuceConnectionFactory(new RedisStandaloneConfiguration("localhost", 6379), clientConfig);
}

今天看了下Lettuce引导有这么一段话的描述:

Is connection pooling necessary?

Lettuce is thread-safe by design which is sufficient for most cases. All Redis user operations are executed single-threaded. Using multiple connections does not impact the performance of an application in a positive way. The use of blocking operations usually goes hand in hand with worker threads that get their dedicated connection. The use of Redis Transactions is the typical use case for dynamic connection pooling as the number of threads requiring a dedicated connection tends to be dynamic.That said, the requirement for dynamic connection pooling is limited. Connection pooling always comes with a cost of complexity and maintenance.

Lettuce Reference Guide5.1.3.RELEASE 地址:https://lettuce.io/core/release/reference/index.html#codecs.multi-threading
Spring Data Redis --Version 2.1.4.RELEASE
spring-data-redis文档路径: https://docs.spring.io/spring-data/redis/docs/current/reference/html/#redis:connectors:lettuce

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,452评论 0 10
  • Objective-C写的项目,不能说100%模仿,主要功能有了,欢迎吐槽...Swift版本的正在写..http...
    张小牛_邪阅读 533评论 2 2
  • 援引:https://blog.csdn.net/xingxuexx/article/details/511320...
    R_X阅读 1,557评论 0 0
  • 何谓教育? 就是成年人向未成年人介绍世界是个什么样子。 教育不成功,就是只有一种声音。 未成年人一开始认识这个世界...
    念念慈慧阅读 211评论 0 0