当前位置:网站首页>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
边栏推荐
猜你喜欢

队列达到最大长度代码实战

Details of impala implementation plan

Introduction to database - Introduction to database

Spark Learning Notes (VI) -- spark core core programming RDD action operator

MySQL:互联网公司常用分库分表方案汇总

How to optimize MySQL

spark学习笔记(五)——sparkcore核心编程-RDD转换算子

代码审查金字塔

Jmeter分布式压测

Deeply understand the underlying data structure and algorithm of MySQL index
随机推荐
$128million! IQM, a Finnish quantum computing company, was supported by the world fund
easyui中textbox在光标位置插入内容
快速排序及优化
Graphic SQL, this is too vivid!
将幕布文章OPML转换为Markdown的方法
docker 创建mysql 8.x容器,支持mac ,arm架构芯片
渗透测试-后渗透-痕迹清理
typescript ts 基础知识之接口、泛型
Activiti5.22.0扩展支持达国产数据库,以GBase据库为例
自己梳理的LocalDateTime的工具类
Learn the recycling mechanism of recyclerview again
[common search questions] 111
Message rejected MQ
JMeter distributed pressure measurement
字节一面:TCP 和 UDP 可以使用同一个端口吗?
《稻盛和夫给年轻人的忠告》阅读笔记
Introduction to database - Introduction to database
Explain工具实际操作
带你了解什么是 Web3.0
基于OpenCV的轮廓检测(2)