You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
redisson/redisson-spring-boot-starter/README.md

221 lines
6.2 KiB
Markdown

# Spring Boot Starter
6 years ago
Integrates Redisson with Spring Boot library. Depends on [Spring Data Redis](https://github.com/redisson/redisson/tree/master/redisson-spring-data#spring-data-redis-integration) module.
8 months ago
Supports Spring Boot 1.3.x - 3.3.x
## Usage
### 1. Add `redisson-spring-boot-starter` dependency into your project:
6 years ago
Maven
6 years ago
```xml
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
7 months ago
<version>3.32.0</version>
</dependency>
6 years ago
```
6 years ago
Gradle
```groovy
7 months ago
compile 'org.redisson:redisson-spring-boot-starter:3.32.0'
```
2 years ago
`redisson-spring-boot-starter` depends on `redisson-spring-data` module compatible with the latest version of Spring Boot. Downgrade `redisson-spring-data` module if necessary to support previous Spring Boot versions:
5 years ago
5 years ago
|redisson-spring-data<br/>module name|Spring Boot<br/>version|
5 years ago
|----------------------------|-------------------|
3 years ago
|redisson-spring-data-16 |1.3.y |
|redisson-spring-data-17 |1.4.y |
|redisson-spring-data-18 |1.5.y |
|redisson-spring-data-2x |2.x.y |
2 years ago
|redisson-spring-data-3x |3.x.y |
5 years ago
For Gradle, you can downgrade to `redisson-spring-data-27` this way:
```groovy
7 months ago
implementation ("org.redisson:redisson-spring-boot-starter:3.32.0") {
8 months ago
exclude group: 'org.redisson', module: 'redisson-spring-data-33'
}
7 months ago
implementation "org.redisson:redisson-spring-data-27:3.32.0"
```
7 years ago
### 2. Add settings into `application.settings` file
2 years ago
Using common Spring Boot 3.x+ settings:
6 years ago
```yaml
spring:
data:
redis:
database:
host:
port:
password:
ssl:
timeout:
connectTimeout:
clientName:
cluster:
nodes:
sentinel:
master:
nodes:
4 years ago
```
2 years ago
Using common Spring Boot up to 2.7.x settings:
2 years ago
```yaml
spring:
2 years ago
redis:
database:
host:
port:
password:
ssl:
timeout:
connectTimeout:
clientName:
cluster:
nodes:
sentinel:
master:
nodes:
2 years ago
```
2 years ago
Using Redisson config file ([single mode](https://github.com/redisson/redisson/wiki/2.-Configuration#262-single-instance-yaml-config-format),
[replicated mode](https://github.com/redisson/redisson/wiki/2.-Configuration#252-replicated-yaml-config-format),
[cluster mode](https://github.com/redisson/redisson/wiki/2.-Configuration#242-cluster-yaml-config-format),
[sentinel mode](https://github.com/redisson/redisson/wiki/2.-Configuration#272-sentinel-yaml-config-format),
2 years ago
[proxy mode](https://github.com/redisson/redisson/wiki/2.-Configuration#292-proxy-mode-yaml-config-format), [multi cluster mode](https://github.com/redisson/redisson/wiki/2.-Configuration/#2102-cluster-yaml-config-format))
2 years ago
4 years ago
```yaml
spring:
4 years ago
redis:
4 years ago
redisson:
4 years ago
file: classpath:redisson.yaml
2 years ago
```
2 years ago
Using Redisson settings ([single mode](https://github.com/redisson/redisson/wiki/2.-Configuration#262-single-instance-yaml-config-format),
[replicated mode](https://github.com/redisson/redisson/wiki/2.-Configuration#252-replicated-yaml-config-format),
[cluster mode](https://github.com/redisson/redisson/wiki/2.-Configuration#242-cluster-yaml-config-format),
[sentinel mode](https://github.com/redisson/redisson/wiki/2.-Configuration#272-sentinel-yaml-config-format),
7 months ago
[proxy mode](https://github.com/redisson/redisson/wiki/2.-Configuration#292-proxy-mode-yaml-config-format), [multi cluster mode](https://github.com/redisson/redisson/wiki/2.-Configuration/#210-multi-cluster-mode), [multi sentinel mode](https://github.com/redisson/redisson/wiki/2.-Configuration/#211-multi-sentinel-mode)):
2 years ago
```yaml
spring:
redis:
redisson:
4 years ago
config: |
clusterServersConfig:
idleConnectionTimeout: 10000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
failedSlaveReconnectionInterval: 3000
failedSlaveCheckInterval: 60000
password: null
subscriptionsPerConnection: 5
clientName: null
loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
subscriptionConnectionMinimumIdleSize: 1
subscriptionConnectionPoolSize: 50
slaveConnectionMinimumIdleSize: 24
slaveConnectionPoolSize: 64
masterConnectionMinimumIdleSize: 24
masterConnectionPoolSize: 64
readMode: "SLAVE"
subscriptionMode: "SLAVE"
nodeAddresses:
- "redis://127.0.0.1:7004"
- "redis://127.0.0.1:7001"
- "redis://127.0.0.1:7000"
scanInterval: 1000
pingConnectionInterval: 0
keepAlive: false
tcpNoDelay: false
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.Kryo5Codec> {}
4 years ago
transportMode: "NIO"
7 years ago
```
4 years ago
### 3. Available Spring Beans:
4 years ago
4 years ago
- `RedissonClient`
- `RedissonRxClient`
- `RedissonReactiveClient`
- `RedisTemplate`
- `ReactiveRedisTemplate`
4 years ago
9 months ago
Upgrade to __[Redisson PRO](https://redisson.pro)__ with **advanced features**.
11 months ago
11 months ago
## Q: How to replace Netty version brought by Spring Boot?
11 months ago
You need to define netty version in properties section of your Maven project.
```xml
<properties>
11 months ago
<netty.version>4.1.107.Final</netty.version>
11 months ago
</properties>
```
## Q: How to disable Redisson?
11 months ago
You may not have Redis in some environments. In this case Redisson can be disabled.
11 months ago
### Using Annotations
11 months ago
Spring Boot 2.7+
```java
@SpringBootApplication
@EnableAutoConfiguration(exclude = {
RedissonAutoConfigurationV2.class})
public class Application {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
```
Spring Boot up to 2.6
11 months ago
```java
@SpringBootApplication
@EnableAutoConfiguration(exclude = {
RedissonAutoConfiguration.class})
public class Application {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
```
11 months ago
11 months ago
### Using `application.yml`
11 months ago
Spring Boot 2.7+
11 months ago
```yaml
spring:
autoconfigure:
exclude:
- org.redisson.spring.starter.RedissonAutoConfigurationV2
11 months ago
```
Spring Boot up to 2.6
```yaml
spring:
autoconfigure:
exclude:
11 months ago
- org.redisson.spring.starter.RedissonAutoConfiguration
```