Add Lettuce Redis driver autoconfiguration

Introduce an alternative autoconfiguration if the lettuce Redis driver is
available. Add Lettuce-specific configuration property options
"spring.redis.lettuce.shutdown-timeout" to control the shutdown timeout
of the lettuce driver. Add documentation for the properties, the
supported drivers, and how to switch between drivers.

Split client-specific properties from spring.redis.pool to
spring.redis.jedis.pool and introduce spring.redis.lettuce namespace.
Deprecate spring.redis.pool property.

See gh-5311
This commit is contained in:
Mark Paluch
2016-03-02 16:04:44 +01:00
committed by Stephane Nicoll
parent 64dae5ec3a
commit 4563da9ac7
11 changed files with 627 additions and 49 deletions

View File

@@ -852,21 +852,36 @@ content into your application; rather pick only the properties that you need.
spring.redis.host=localhost # Redis server host.
spring.redis.password= # Login password of the redis server.
spring.redis.ssl=false # Enable SSL support.
spring.redis.pool.max-active=8 # Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.pool.max-idle=8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.pool.max-wait=-1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
spring.redis.jedis.pool.max-active=8 # Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.jedis.pool.max-idle=8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.jedis.pool.max-wait=-1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.jedis.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
spring.redis.port=6379 # Redis server port.
spring.redis.sentinel.master= # Name of Redis server.
spring.redis.sentinel.nodes= # Comma-separated list of host:port pairs.
spring.redis.timeout=0 # Connection timeout in milliseconds.
spring.redis.ssl.enabled=false # Enable SSL support.
spring.redis.ssl.verify-peer=true # Enable SSL peer verification.
spring.redis.ssl.start-tls=false # Enable StartTLS support.
# REDIS JEDIS DRIVER
spring.redis.jedis.pool.max-active=8 # Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.jedis.pool.max-idle=8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.jedis.pool.max-wait=-1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.jedis.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
# REDIS LETTUCE DRIVER
spring.redis.lettuce.pool.max-active=8 # Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit.
spring.redis.lettuce.pool.max-idle=8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections.
spring.redis.lettuce.pool.max-wait=-1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
spring.redis.lettuce.pool.min-idle=0 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
spring.redis.lettuce.shutdown-timeout=2000 # Shutdown timeout in milliseconds.
# TRANSACTION ({sc-spring-boot-autoconfigure}/transaction/TransactionProperties.{sc-ext}[TransactionProperties])
spring.transaction.default-timeout= # Default transaction timeout in seconds.
spring.transaction.rollback-on-commit-failure= # Perform the rollback on commit failures.
# ----------------------------------------
# INTEGRATION PROPERTIES
# ----------------------------------------

View File

@@ -3074,3 +3074,44 @@ but the rest of it is normal for a Spring application in Servlet 2.5. Example:
In this example we are using a single application context (the one created by the context
listener) and attaching it to the `DispatcherServlet` using an init parameter. This is
normal in a Spring Boot application (you normally only have one application context).
[[howto-use-lettuce-instead-of-jedis]]
=== Use Lettuce instead of Jedis
The Spring Boot Redis starter (`spring-boot-starter-data-redis` in particular) uses
https://github.com/xetorthio/jedis/[Jedis] by default. You need to exclude that dependency
and include the https://github.com/lettuce-io/lettuce-core/[Lettuce] one instead. Spring Boot provides a managed dependency
to help make this process as easy as possible.
Example in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</dependency>
----
Example in Gradle:
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
----
configurations {
compile.exclude module: "jedis"
}
dependencies {
compile("io.lettuce:lettuce-core:{lettuce.version}")
// ...
}
----

View File

@@ -3262,10 +3262,11 @@ http://projects.spring.io/spring-data[projects.spring.io/spring-data].
=== Redis
http://redis.io/[Redis] is a cache, message broker and richly-featured key-value store.
Spring Boot offers basic auto-configuration for the
https://github.com/xetorthio/jedis/[Jedis] client library and abstractions on top of it
provided by https://github.com/spring-projects/spring-data-redis[Spring Data Redis]. There
https://github.com/xetorthio/jedis/[Jedis] and and https://github.com/mp911de/lettuce/[Lettuce]
client library and abstractions on top of it provided by
https://github.com/spring-projects/spring-data-redis[Spring Data Redis]. There
is a `spring-boot-starter-data-redis` '`Starter`' for collecting the dependencies in a
convenient way.
convenient way that uses https://github.com/xetorthio/jedis/[Jedis] by default.