How to integrate Redisson with micro service framework SpringBoot
Most people do not understand the knowledge points of this article "how to integrate SpringBoot into Redisson", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how to integrate Redisson with SpringBoot in Micro Services Framework".
Comparison of advantages and disadvantages of Redisson, Jedis and Lettuce
(1) Redisson
Advantages:
The distributed characteristics and extensible Java data structure are realized, which is suitable for distributed development.
API thread safety
Event-driven communication based on Netty framework, which can be called asynchronously.
Disadvantages:
API is more abstract and expensive to learn to use.
(2) Jedis
Advantages:
API that provides more comprehensive operational features of Redis
API basically corresponds to the instructions of Redis, which is easy to use and easy to understand.
Disadvantages:
Synchronous blocking IO
Asynchrony is not supported
Thread is not safe.
(3) Lettuce
Advantages:
Thread safety
Event-driven communication based on Netty framework, which can be called asynchronously
Suitable for distributed caching.
Disadvantages:
API is more abstract and expensive to learn to use.
Among them, Jedis is the most commonly used (indeed very simple), especially for many single applications or pseudo-distributed applications.
SpringBoot integrates Redisson
1. Add Maven dependency org.redisson redisson-spring-boot-starter 3.11.4 2. Configuration file spring: redis: host: 127.0.0.1 port: 6379 database: 0 timeout: 50003. Add configuration class import org.redisson.Redisson;import org.redisson.api.RedissonClient;import org.redisson.config.Config;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.autoconfigure.data.redis.RedisProperties;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Configurationpublic class RedissonConfig {@ Autowired private RedisProperties redisProperties; @ Bean public RedissonClient redissonClient () {Config config = new Config () String redisUrl = String.format ("redis://%s:%s", redisProperties.getHost () + ", redisProperties.getPort () +"); config.useSingleServer (). SetAddress (redisUrl) .setPassword (redisProperties.getPassword ()); config.useSingleServer (). SetDatabase (3); return Redisson.create (config);}} 4. Code testing (simple access) import org.redisson.api.RedissonClient;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping ("/ redisson") public class RedissonController {@ Autowired private StringRedisTemplate stringRedisTemplate @ GetMapping ("/ save") public String save () {stringRedisTemplate.opsForValue () .set ("key", "redisson"); return "save ok";} @ GetMapping ("/ get") public String get () {return stringRedisTemplate.opsForValue () .get ("key") }} the above is the content of this article on "how SpringBoot integrates Redisson". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about related knowledge, please follow the industry information channel.