In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "the method of Springboot redis integration and configuration". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "the method of Springboot redis integration and configuration" can help you solve your doubts.
1. Redis installation
This article uses docker to install redis, if the local installation is also very convenient, directly download the installation package and then start the cmd window command line.
Pull the image
Docker pull redis:4.0
Start mirroring
Docker run-itd-- name redis-01-p 6379 name redis-01 6379 # Mirror id
Release port
Firewall-cmd-- state # View Firewall status systemctl start firewalld.service # start Firewall firewall-cmd-- zone=public-- add-port=6379/tcp-- permanent # release Port system restart firewalld.service # restart Firewall firewall-cmd-- reload # reload configuration firewall-cmd-- list-all # View Open Port 2, Spring boot introduction 2.1, Introduce maven dependency org.springframework.boot spring-boot-starter-data-redis com.fasterxml.jackson.core jackson-databind
What is introduced here is the official starter. In the past, when people used jedis, they could change their ideas more personally.
2.2 、 Basic configuration spring.redis.host=192.168.1.37#Redis server connection port spring.redis.port=6379#Redis server connection password (default is empty) maximum number of spring.redis.password=# connection pool connections (use negative values for no limit) spring.redis.pool.max-active=8# connection pool maximum blocking wait time (use negative values for no limit) spring.redis.pool.max-wait=-1# connection pool Minimum idle connection spring.redis.pool.max-idle=8# connection timeout (milliseconds) spring.redis.timeout=30000 in the maximum idle connection spring.redis.pool.min-idle=0# connection pool
The specific and detailed configuration changes according to individual needs. In fact, springboot has a default configuration, which can be used without configuration.
2.3.The RedisServicepackage com.ssk.shop.bll;/** * redis API * / public interface IRedisBll {/ * Storage data * / void set (String key, String value); / * * get data * / String get (String key); / * * set expiration time * / boolean expire (String key, long expire); / * * Delete data * / void remove (String key) / * * self-increment operation * @ param delta auto-increment step * / Long increment (String key, long delta);}
Impl
Package com.ssk.shop.bll.impl;import com.ssk.shop.bll.IRedisBll;import org.springframework.data.redis.core.StringRedisTemplate;import org.springframework.stereotype.Service;import javax.annotation.Resource;import java.util.concurrent.TimeUnit;@Servicepublic class IRedisBllImpl implements IRedisBll {@ Resource private StringRedisTemplate stringRedisTemplate; @ Override public void set (String key, String value) {stringRedisTemplate.opsForValue () .set (key, value);} @ Override public String get (String key) {return stringRedisTemplate.opsForValue () .get (key) } @ Override public boolean expire (String key, long expire) {return stringRedisTemplate.expire (key, expire, TimeUnit.SECONDS);} @ Override public void remove (String key) {stringRedisTemplate.delete (key);} @ Override public Long increment (String key, long delta) {return stringRedisTemplate.opsForValue (). Increment (key,delta);}}
Some basic methods can be encapsulated to make some ordinary operations more convenient to achieve.
Summary: redis is a good cache processing solution, the project can always allow users to cache some commonly used information, reduce the pressure of access to the database, for some second kill programs are also optional, so far in the project will be some permissions and token with redis unique login control (effective with a single token).
After reading this, the article "methods of Springboot redis Integration and configuration" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.