In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Spring how to operate Redis Repositoy, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Spring operation Redis Repositoy
Mode of operation
Redis Repository usage
Code warehouse
Introduction to demo function
Data
Mode of operation
There are several ways for spring to operate redis. Here are the two most commonly used ways, both of which are synchronized.
RedisTemplate
Redis Repository
The above is the result of the encapsulation of the redis client by spring. The redis client is divided into different dependencies according to different spring versions. The commonly used ones are jedis and lettuce.
Spring also supports responsive access to redis server since version 5.0, but it may not be necessary. It is mainly supported by encapsulating lettuce as a redis client. Jedis does not support reactive access to redis server.
Redis Repository usage
Code warehouse
Address: GitHub
Introduction to demo function
Use spring-boot-starter-data-redis:2.1.2
Easy to operate redis database by using Redis Repository feature
Object storage, key-value
Set obsolete time
Operation flow
A redis server, version > = 2.8,
A springboot with web,lombok,redis and other components, springboot version > 2.0
Persistent object domain
Dao layer, repository
Source code reading
View RedisConfig
@ Configuration represents the configuration class
@ EnableRedisRepositories means to enable the Redis Repository feature
RedisConnectionFactory is the connection pool for redis. Configuring RedisTemplate requires
RedisTemplate as a dependency on Redis Repository
Check the person class in domain
@ RedisHash (people) identifies the prefix of the key; @ Id identifies this field as the unique identity of the people and the second half of the key.
@ TimeToLive indicates the expiration time. Once expired, the object of the redis corresponding to the key will be removed.
View AppController
Just look at the main logic, which is just an entrance to the web interface.
It contains the use of curd for operating redis repository and setting the expiration time
After reading the above, have you mastered how Spring operates Redis Repositoy? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.