当前位置:网站首页>Introduction to redis
Introduction to redis
2022-07-27 03:35:00 【I'm master CV】
springboot Integrate redis
1. Import corresponding dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>2.springboot Medium application.properties File corresponding configuration
#Redis Server address
spring.redis.host= Yours redis Of ip Address
#Redis Server connection port
spring.redis.port= Yours redis port
#Redis Database index ( The default is 0)
spring.redis.database= 0
# Connection timeout ( millisecond )
spring.redis.timeout=1800000
# Maximum number of connections in connection pool ( Use a negative value to indicate that there is no limit )
spring.redis.lettuce.pool.max-active=20
# Maximum blocking waiting time ( A negative number means no limit )
spring.redis.lettuce.pool.max-wait=-1
# The maximum free connection in the connection pool
spring.redis.lettuce.pool.max-idle=5
# The smallest free connection in the connection pool
spring.redis.lettuce.pool.min-idle=0
spring.redis.password= Yours redis password The corresponding order , Detailed commands can be searched and operated by yourself

3. stay springboot Experiment in the test class
@SpringBootTest
public class redistest {
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Test
public void test1(){
redisTemplate.opsForValue().set("1","1");
}
}Test success

SpringDataRedis serialize
redis You can take whatever you want Object Write... As a value redis, But it will Object The sequence is converted to byte form , By default JDK serialize , The results are as follows

Poor readability , Memory usage is also very large , It's very painful
Convert it to JSON String can solve this problem perfectly
have access to fastjson package , take Object Objects of type are directly converted to json character string , Import the following dependencies
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
take Object Object conversion to json character string JSON.toJSONString(Object)
redisTemplate.opsForValue().set("TOKEN_"+token, JSON.toJSONString(sysUsers),1, TimeUnit.DAYS);take json The string is inversely converted to the original object
SysUsers sysUsers=JSON.parseObject(userJson,SysUsers.class);To complete redis Serialization and deserialization , Awesome
边栏推荐
- 技术风向标 | 云原生技术架构成熟度模型解读
- Deep learning vocabulary embedded, beam search
- 百融榕树数据分析拆解方法
- 微信小程序生成Excel
- [1206. Design skip table]
- [common search questions] 111
- Acwing 2074. Countdown simulation
- 常见弱口令大全
- How many implementation postures of delay queue? Daily essential skills!
- How to design the red table of database to optimize the performance
猜你喜欢

flask_restful中reqparse解析器继承

$128million! IQM, a Finnish quantum computing company, was supported by the world fund

Comprehensive care analysis lyriq Ruige battery safety design

Jmeter分布式压测

延时队列的几种实现姿势?日常必备技能!

Graphic SQL, this is too vivid!

Deep learning vocabulary embedded, beam search

Pytorch损失函数总结

Quick sequencing and optimization

数字孪生应用及意义对电力的主要作用,概念价值。
随机推荐
若依的环境的部署以及系统的运行
基于OpenCV的轮廓检测(1)
Wechat applet generation Excel
Double disk: the main differences between DFS and BFS, the differences in ideology, and the differences in code implementation
代码审查金字塔
MySQL:互联网公司常用分库分表方案汇总
[flask] the server obtains the file requested by the client
百融榕树数据分析拆解方法
注解@Autowired和@Resource的区别总结
“满五唯一”和“满二唯一”是什么?有什么不同?
[regular] judgment, mobile number, ID number
Activiti5.22.0 extension supports domestic databases, taking gbase database as an example
Take you to know what Web3.0 is
Pytoch loss function summary
Post responsibilities of safety officer and environmental protection officer
Technology vane | interpretation of cloud native technology architecture maturity model
What are "full five unique" and "full two unique"? Any difference?
常见弱口令大全
Leetcode 207. curriculum (July 26, 2022)
mysql底层数据结构