notes
3, SpringBoot2.x integration redis combat explain
Summary: springboot-starter integrated combat reids
1, the official website: https: //docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/ # boot-features-redis
cluster document: HTTPS: //docs.spring.io/spring-data/data-redis/docs/current/reference/html/#cluster
2, springboot integration redis its dependencies introduced
<dependency>
<groupId > org.springframework.boot </ the groupId>
<the artifactId> Starter-Spring-Boot-Data-Redis </ the artifactId>
</ dependency>
. 3, relevant profile configuration
# ========= redis basic configuration = ========
spring.redis.database = 0
spring.redis.host = 127.0.0.1
spring.redis.port=6390
# Connection time units ms (milliseconds)
spring.redis.timeout = 3000
# ========= ========= provided Redis thread pool
# connection pool maximum idle connection, the default value also 8.
= 200 is IDLE-spring.redis.pool.max
# minimum connection pool idle connections, the default value is 0.
= 200 is IDLE-spring.redis.pool.min
# If the assignment is -1, not to limit; maxActive pool have been allocated a jedis example, the pool state at this time is exhausted (exhausted).
Active-2000 = spring.redis.pool.max
# wait a maximum time available connections, in milliseconds, the default value is -1, never expires
spring.redis.pool.max = the wait-1000
. 4, and explanation of common type redistemplate cache practical operation (use automatic injector)
1, injection template
@Autowired
Private StirngRedisTemplate strTplRedis
2, the type of String, List, Hash, Set, ZSet
a corresponding method are opsForValue (), opsForList (), opsForHash (), opsForSet (), opsForZSet ()
Start
To see if a port is occupied
create a basis for comparison of project
JsonData response is the result of a package of le
first step
You can see the official documentation
https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-redis
click on the Spring Data Redis depend on the
reference address cluster deployment
https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#cluster
The introduction of dependence
Configuration related configuration files
3, the relevant profile configuration
# ========= redis Basic Configuration =========
spring.redis.database = 0
spring.redis.host = 127.0.0.1
spring.redis.port = 6390
# connection time units of ms (milliseconds)
spring.redis.timeout = 3000
# ========= ========= provided Redis thread pool
# connection pool maximum idle connection, default value is 8.
= 200 is IDLE-spring.redis.pool.max
# minimum connection pool idle connections, the default value is 0.
= 200 is IDLE-spring.redis.pool.min
# If the assignment is -1, not to limit; maxActive pool have been allocated a jedis example, the pool state at this time is exhausted (exhausted).
Active-2000 = spring.redis.pool.max
# maximum time to wait for an available connection, in milliseconds, the default value is -1, never expires
spring.redis.pool.max-wait = 1000
controller
RedisTemplate help us to operate Redis. opsForValue is a simple form of key value
there which a lot of ways
jsonData provides some return values of
Start the test
There is also no configuration redis profile. So used are default values
get from redis obtain key is the value of name
in this line to add a breakpoint debugging
To copy the configuration files over.
Copied these configurations do some optimization.
Start the application for testing
The default port is 6379 redis
visit again. Get the value, which indicates that the profile is successfully configured.