当前位置:网站首页>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
边栏推荐
- 若依框架代码生成详解
- How to uniquely identify a user SQL in Youxuan database cluster
- 智能体重秤方案主控采用CSU18M91
- typescript ts 基础知识之接口、泛型
- 数字孪生实际应用:智慧城市项目建设解决方案
- 记录一次,php程序访问系统文件访问错误的问题
- 【无标题】JDBC连接数据库读超时
- Unity game, the simplest solution of privacy agreement! Just 3 lines of code! (Reprinted)
- Redis spike case, learn from Shang Silicon Valley teacher in station B
- Code review pyramid
猜你喜欢

Post responsibilities of safety officer and environmental protection officer

【树链剖分】2022杭电多校2 1001 Static Query on Tree

mysql出现不存在错误

一种分布式深度学习编程新范式:Global Tensor

数据库概论 - 数据库的介绍

Graphic SQL, this is too vivid!

JMeter distributed pressure measurement

spark学习笔记(四)——sparkcore核心编程-RDD

Code review pyramid

It's too strong. An annotation handles the data desensitization returned by the interface
随机推荐
spark学习笔记(六)——sparkcore核心编程-RDD行动算子
Byte side: can TCP and UDP use the same port?
[common search questions] 111
30 minutes to thoroughly understand the synchronized lock upgrade process
Acwing 2074. Countdown simulation
一种分布式深度学习编程新范式:Global Tensor
Mysql: summary of common sub database and sub table schemes of Internet companies
注解@Autowired和@Resource的区别总结
阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题
How to uniquely identify a user SQL in Youxuan database cluster
DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库
Leetcode 207. curriculum (July 26, 2022)
PIP3 setting alicloud
spark学习笔记(五)——sparkcore核心编程-RDD转换算子
MySQL Chinese failure
How to optimize MySQL
Practice of online problem feedback module (XV): realize the function of online updating feedback status
Submodule cache cache failure
Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks
Code review pyramid