The article directories

  • Introduction to the
  • Rely on
  • configuration
  • use

Introduction to the

When I first learned Redis, I used the native Jedis. Each time I used a new object and then used it. After integrating with SpringBoot, it was hosted by Spring, and then it could be automatically assembled. We want to use just importing dependencies and simple configuration.

Rely on


2.2.7.RELEASE

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
Copy the code

Click on this dependency to see that the underlying use is lettuce

< the dependency > < groupId > IO. Lettuce < / groupId > < artifactId > lettuce - core < / artifactId > < version > 5.2.2. RELEASE < / version > <scope>compile</scope> </dependency>Copy the code

configuration

Also, the configurations used are also lettuce

Host =127.0.0.1 spring.redis.port=6379 Spring. Redis. Lettuce. Pool. Max - active = 8 # connection pool biggest jam waiting time (use a negative value indicates no limit) spring. Redis. Lettuce. The pool. The Max - wait = 1 # the maximum idle connections in the connection pool Spring. Redis. Lettuce. Pool. Max - idle = 8 # connection pool minimum idle connections in the spring. The redis. Lettuce. Pool. Min - idle = 0Copy the code

use

// add RedisTemplate @autowired RedisTemplate RedisTemplate; // redisTemplate operates on different data types // opsForValue operates on strings similar to String // opsForList operates on list similar to list // etc... redisTemplate.opsForValue().set("k1","v1"); System.out.println(redisTemplate.opsForValue().get("k1"));Copy the code