当前位置: 首页 > news >正文

在Spring Boot微服务使用RedisTemplate操作Redis

记录:400

场景:在Spring Boot微服务使用RedisTemplate操作Redis缓存和队列。 使用ValueOperations操作Redis String字符串;使用ListOperations操作Redis List列表,使用HashOperations操作Redis Hash哈希散列,使用SetOperations操作Redis Set集合(无序集合),使用ZSetOperations操作Redis Zset(有序集合)。

版本:JDK 1.8,Spring Boot 2.6.3,redis-6.2.5

1.微服务中Redis配置信息

1.1在application.yml中Redis配置信息

spring:redis:host: 192.168.19.203port: 28001password: 12345678timeout: 50000

1.2加载简要逻辑

Spring Boot微服务在启动时,自动注解机制会读取application.yml的注入到RedisProperties对象。在Spring环境中就能取到Redis相关配置信息了。

类全称:org.springframework.boot.autoconfigure.data.redis.RedisProperties

1.3在pom.xml添加依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

2.配置RedisTemplate

2.1配置RedisTemplate

@Configuration
public class RedisConfig {@Bean("redisTemplate")public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {// 1.创建RedisTemplate对象RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();// 2.加载Redis配置redisTemplate.setConnectionFactory(lettuceConnectionFactory);// 3.配置key序列化RedisSerializer<?> stringRedisSerializer = new StringRedisSerializer();redisTemplate.setKeySerializer(stringRedisSerializer);redisTemplate.setHashKeySerializer(stringRedisSerializer);// 4.配置Value序列化Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);ObjectMapper objMapper = new ObjectMapper();objMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);objMapper.activateDefaultTyping(objMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL);jackson2JsonRedisSerializer.setObjectMapper(objMapper);redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);// 5.初始化RedisTemplateredisTemplate.afterPropertiesSet();return redisTemplate;}@Beanpublic ValueOperations<String, Object> valueOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForValue();}@Beanpublic ListOperations<String, Object> listOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForList();}@Beanpublic HashOperations<String, Object, Object> hashOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForHash();}@Beanpublic SetOperations<String, Object> setOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForSet();}@Beanpublic ZSetOperations<String, Object> zSetOperations(RedisTemplate<String, Object> redisTemplate) {return redisTemplate.opsForZSet();}
}

2.2解析

在配置RedisTemplate后,在Spring环境中,可以@Autowired自动注入方式注入操作Redis对象。比如:RedisTemplate、ValueOperations、ListOperations、HashOperations、SetOperations、ZSetOperations。

3.直接使用RedisTemplate操作

3.1简要说明

使用RedisTemplate的boundValueOps方法操作字符串,常用操作:增、查、改、删、设置超时等。

3.2操作示例

@RestController
@RequestMapping("/hub/example/load")
@Slf4j
public class LoadController {@Autowiredprivate RedisTemplate redisTemplate;/*** 操作缓存方式,直接使用RedisTemplate* 对应写命令: SET key value* 对应读命令: GET key*/@GetMapping("/redisTemplate")public Object loadData01() {log.info("RedisTemplate操作开始...");// 1.增redisTemplate.boundValueOps("CityInfo:Hangzhou01").set("杭州");// 2.查Object result01 = redisTemplate.boundValueOps("CityInfo:Hangzhou01").get();log.info("result01 = " + result01.toString());// 3.改redisTemplate.boundValueOps("CityInfo:Hangzhou01").set("杭州-西湖");// 4.删redisTemplate.delete("CityInfo:Hangzhou01");// 5.1设置超时(方式一)redisTemplate.boundValueOps("CityInfo:Hangzhou01").set("杭州-西湖");redisTemplate.expire("CityInfo:Hangzhou01", 5, TimeUnit.MINUTES);// 5.2设置超时(方式二)redisTemplate.boundValueOps("CityInfo:Hangzhou01-01").set("杭州", 5, TimeUnit.MINUTES);log.info("RedisTemplate操作结束...");return "执行成功";}
}

3.3测试验证

使用Postman测试。

请求RUL:http://127.0.0.1:18205/hub-205-redis/hub/example/load/redisTemplate

4.使用ValueOperations操作Redis String字符串

4.1简要说明

使用ValueOperations操作字符串,常用操作:增、查、改、删、设置超时等。

4.2操作示例

@RestController
@RequestMapping("/hub/example/load")
@Slf4j
public class LoadController {@Autowiredprivate RedisTemplate redisTemplate;@Autowiredprivate ValueOperations valueOperations;/*** 操作String,使用ValueOperations* 对应写命令: SET key value* 对应读命令: GET key*/@GetMapping("/valueOperations")public Object loadData02() {log.info("ValueOperations操作开始...");// 1.增valueOperations.set("CityInfo:Hangzhou02", "杭州");valueOperations.set("CityInfo:Hangzhou02", "苏州");// 2.查Object result01 = valueOperations.get("CityInfo:Hangzhou02");log.info("result01 = " + result01.toString());// 3.改valueOperations.set("CityInfo:Hangzhou02", "杭州-西湖");// 4.删String result02 = (String) valueOperations.getAndDelete("CityInfo:Hangzhou02");redisTemplate.delete("CityInfo:Hangzhou02");// 5.1设置超时(方式一)valueOperations.set("CityInfo:Hangzhou02", "杭州-西湖");valueOperations.getAndExpire("CityInfo:Hangzhou02", 5, TimeUnit.MINUTES);// 5.2设置超时(方式二)valueOperations.set("CityInfo:Hangzhou02", "杭州-西湖");redisTemplate.expire("CityInfo:Hangzhou02", 10, TimeUnit.MINUTES);// 6.查询Value的字节大小Long size =valueOperations.size("CityInfo:Hangzhou02");System.out.println("缓存字节大小,size="+size +" bytes");log.info("ValueOperations操作结束...");return "执行成功";}
}

4.3测试验证

使用Postman测试。

请求RUL:http://127.0.0.1:18205/hub-205-redis/hub/example/load/valueOperations

5.使用ListOperations操作Redis List列表

5.1简要说明

使用ListOperationsRedis List列表,常用操作:增、查、删、设置超时等。

5.2操作示例

@RestController
@RequestMapping("/hub/example/load")
@Slf4j
public class LoadController {@Autowiredprivate RedisTemplate redisTemplate;@Autowiredprivate ListOperations listOperations;/*** 操作List,使用ListOperations* 对应写命令: LPUSH 队列名称 值* 对应读命令: LPOP 队列名称* 对应写命令: RPUSH 队列名称 值* 对应读命令: RPOP 队列名称*/@GetMapping("/listOperations")public Object loadData03() {log.info("ListOperations操作开始...");// 1.增listOperations.leftPush("CityInfo:Hangzhou03", "杭州");listOperations.rightPush("CityInfo:Hangzhou03", "苏州");// 2.查,查出队列指定范围元素,不会删除队列里面数据,(0,-1)查出全部元素listOperations.leftPush("CityInfo:Hangzhou03", "杭州");listOperations.leftPush("CityInfo:Hangzhou03", "苏州");List cityList = redisTemplate.boundListOps("CityInfo:Hangzhou03").range(0, -1);cityList.forEach((value)->{System.out.println("value="+value);});// 3.取,逐个取出队列元素(取出一个元素后,队列就没有这个元素了)Object city01 = listOperations.leftPop("CityInfo:Hangzhou03");Object city02 = listOperations.rightPop("CityInfo:Hangzhou03");log.info("city01=" + city01 + ",city02=" + city02);// 4.删listOperations.leftPush("CityInfo:Hangzhou03", "杭州");listOperations.leftPush("CityInfo:Hangzhou03", "苏州");redisTemplate.delete("CityInfo:Hangzhou03");// 5.设置超时listOperations.leftPush("CityInfo:Hangzhou03", "上海");redisTemplate.boundValueOps("CityInfo:Hangzhou03").expire(5, TimeUnit.MINUTES);redisTemplate.expire("CityInfo:Hangzhou03", 10, TimeUnit.MINUTES);// 6.查询List的元素个数Long size =listOperations.size("CityInfo:Hangzhou03");System.out.println("查询List的元素个数,size="+size);log.info("ListOperations操作结束...");return "执行成功";}
}

5.3测试验证

使用Postman测试。

请求RUL:http://127.0.0.1:18205/hub-205-redis/hub/example/load/listOperations

6.使用HashOperations操作Redis Hash哈希散列

6.1简要说明

使用HashOperations操作Redis Hash哈希散列,常用操作:增、查、改、删、设置超时等。

6.2操作示例

@RestController
@RequestMapping("/hub/example/load")
@Slf4j
public class LoadController {@Autowiredprivate RedisTemplate redisTemplate;@Autowiredprivate HashOperations hashOperations;/*** 操作Hash,使用HashOperations* 对应写命令: HMSET* 对应读命令: HGETALL* 本质就是在一个key对应存储了一个Map*/@GetMapping("/hashOperations")public Object loadData04() {log.info("HashOperations操作开始...");// 1.增hashOperations.put("CityInfo:Hangzhou04", "hangzhou", "杭州");hashOperations.put("CityInfo:Hangzhou04", "suzhou", "苏州");// 2.1查-获取map键值对数据Map resultMap = hashOperations.entries("CityInfo:Hangzhou04");resultMap.forEach((key, value) -> {System.out.println("key=" + key + ",value=" + value);});// 2.2查-获取Map的全部keySet set = hashOperations.keys("CityInfo:Hangzhou04");set.forEach((key) -> {System.out.println("key=" + key);});// 2.3查-获取Map的全部valueList list = hashOperations.values("CityInfo:Hangzhou04");list.forEach((value) -> {System.out.println("value=" + value);});// 3.改hashOperations.put("CityInfo:Hangzhou04", "hangzhou", "杭州-西湖");// 4.1删,(删除指定值)hashOperations.delete("CityInfo:Hangzhou04", "hangzhou", "suzhou");// 4.2删,(删除全部)redisTemplate.delete("CityInfo:Hangzhou04");// 5.设置超时hashOperations.put("CityInfo:Hangzhou04", "hangzhou", "杭州");redisTemplate.boundValueOps("CityInfo:Hangzhou04").expire(5, TimeUnit.MINUTES);redisTemplate.expire("CityInfo:Hangzhou04", 10, TimeUnit.MINUTES);// 6.查询Hash的元素个数Long size =hashOperations.size("CityInfo:Hangzhou04");System.out.println("查询Hash的元素个数,size="+size);log.info("HashOperations操作结束...");return "执行成功";}
}

6.3测试验证

使用Postman测试。

请求RUL:http://127.0.0.1:18205/hub-205-redis/hub/example/load/hashOperations

7.使用SetOperations操作Redis Set集合(无序集合)

7.1简要说明

使用SetOperations操作Redis Set集合(无序集合),常用操作:增、查、删、设置超时等。

7.2操作示例

@RestController
@RequestMapping("/hub/example/load")
@Slf4j
public class LoadController {@Autowiredprivate RedisTemplate redisTemplate;@Autowiredprivate SetOperations setOperations;/*** 操作ZSet,使用ZSetOperations,有序排列且无重复数据* 对应写命令: ZADD* 对应读命令: SPOP*/@GetMapping("/zSetOperations")public Object loadData06() {log.info("ZSetOperations操作开始...");// 1.增zSetOperations.add("CityInfo:Hangzhou06", "杭州", 20);zSetOperations.add("CityInfo:Hangzhou06", "苏州", 10);zSetOperations.add("CityInfo:Hangzhou06", "上海", 30);zSetOperations.add("CityInfo:Hangzhou06", "北京", 101);zSetOperations.add("CityInfo:Hangzhou06", "宁波", 999);// 2.1查(通过下标查值,从0开始取第一个值)Set set = zSetOperations.range("CityInfo:Hangzhou06", 1, 4);set.forEach((value) -> {System.out.println("value=" + value);});// 2.2查(通过Score查值)set = zSetOperations.rangeByScore("CityInfo:Hangzhou06", 29, 60);set.forEach((value) -> {System.out.println("value=" + value);});// 3.改zSetOperations.add("CityInfo:Hangzhou06", "杭州", 99);// 4.1取(取出Score最大的值,取出后队列中值会删除)ZSetOperations.TypedTuple obj1 = zSetOperations.popMax("CityInfo:Hangzhou06");System.out.println("取出最大值,value=" + obj1.getValue() + ",Score=" + obj1.getScore());// 4.2取(取出Score最小的值,取出后队列中值会删除)ZSetOperations.TypedTuple obj2 = zSetOperations.popMin("CityInfo:Hangzhou06");System.out.println("取出最小值,value=" + obj2.getValue() + ",Score=" + obj2.getScore());// 5.1删除指定值zSetOperations.remove("CityInfo:Hangzhou06", "上海");// 5.2按照Score分数大小删除zSetOperations.removeRangeByScore("CityInfo:Hangzhou06", 1, 100);// 5.3删(删除全部)redisTemplate.delete("CityInfo:Hangzhou06");// 6.设置超时zSetOperations.add("CityInfo:Hangzhou06", "杭州", 21);zSetOperations.add("CityInfo:Hangzhou06", "苏州", 11);redisTemplate.boundValueOps("CityInfo:Hangzhou06").expire(5, TimeUnit.MINUTES);redisTemplate.expire("CityInfo:Hangzhou06", 10, TimeUnit.MINUTES);// 7.查询ZSet的元素个数Long size =zSetOperations.size("CityInfo:Hangzhou06");System.out.println("查询ZSet的元素个数,size="+size);log.info("ZSetOperations操作结束...");return "执行成功";}
}

7.3测试验证

使用Postman测试。

请求RUL:http://127.0.0.1:18205/hub-205-redis/hub/example/load/setOperations

8.使用ZSetOperations操作Redis Zset(有序集合)

8.1简要说明

使用ZSetOperations操作Redis Zset(有序集合),常用操作:增、查、改、删、设置超时等。

8.2操作示例

@RestController
@RequestMapping("/hub/example/load")
@Slf4j
public class LoadController {@Autowiredprivate RedisTemplate redisTemplate;@Autowiredprivate ZSetOperations zSetOperations;/*** 操作ZSet,使用ZSetOperations,有序排列且无重复数据* 对应写命令: ZADD*/@GetMapping("/zSetOperations")public Object loadData06() {log.info("ZSetOperations操作开始...");// 1.增zSetOperations.add("CityInfo:Hangzhou06", "杭州", 20);zSetOperations.add("CityInfo:Hangzhou06", "苏州", 10);zSetOperations.add("CityInfo:Hangzhou06", "上海", 30);zSetOperations.add("CityInfo:Hangzhou06", "北京", 101);zSetOperations.add("CityInfo:Hangzhou06", "宁波", 999);// 2.1查(通过下标查值,从0开始取第一个值)Set set = zSetOperations.range("CityInfo:Hangzhou06", 1, 4);set.forEach((value) -> {System.out.println("value=" + value);});// 2.2查(通过Score查值)set = zSetOperations.rangeByScore("CityInfo:Hangzhou06", 29, 60);set.forEach((value) -> {System.out.println("value=" + value);});// 3.改zSetOperations.add("CityInfo:Hangzhou06", "杭州", 99);// 4.1取(取出Score最大的值,取出后队列中值会删除)ZSetOperations.TypedTuple obj1 = zSetOperations.popMax("CityInfo:Hangzhou06");System.out.println("取出最大值,value=" + obj1.getValue() + ",Score=" + obj1.getScore());// 4.2取(取出Score最小的值,取出后队列中值会删除)ZSetOperations.TypedTuple obj2 = zSetOperations.popMin("CityInfo:Hangzhou06");System.out.println("取出最小值,value=" + obj2.getValue() + ",Score=" + obj2.getScore());// 5.1删除指定值zSetOperations.remove("CityInfo:Hangzhou06", "上海");// 5.2按照Score分数大小删除zSetOperations.removeRangeByScore("CityInfo:Hangzhou06", 1, 100);// 5.3删(删除全部)redisTemplate.delete("CityInfo:Hangzhou06");// 6.设置超时zSetOperations.add("CityInfo:Hangzhou06", "杭州", 21);zSetOperations.add("CityInfo:Hangzhou06", "苏州", 11);redisTemplate.boundValueOps("CityInfo:Hangzhou06").expire(5, TimeUnit.MINUTES);redisTemplate.expire("CityInfo:Hangzhou06", 10, TimeUnit.MINUTES);// 7.查询ZSet的元素个数Long size =zSetOperations.size("CityInfo:Hangzhou06");System.out.println("查询ZSet的元素个数,size="+size);log.info("ZSetOperations操作结束...");return "执行成功";}
}

8.3测试验证

使用Postman测试。

请求RUL:http://127.0.0.1:18205/hub-205-redis/hub/example/load/zSetOperations

9.可视化工具RedisDesktopManager

在可视化工具RedisDesktopManager中,可以查询Redis相关信息。

在ZSetOperations操作时,名称:CityInfo:Hangzhou06,以冒号分割,在RedisDesktopManager中会自动转换为文件夹方式展现。有多级冒号,就有多个文件夹。

TTL:591,是缓存超期时间,单位一般为秒。

 以上,感谢。

2023年4月12日

相关文章:

在Spring Boot微服务使用RedisTemplate操作Redis

记录&#xff1a;400 场景&#xff1a;在Spring Boot微服务使用RedisTemplate操作Redis缓存和队列。 使用ValueOperations操作Redis String字符串&#xff1b;使用ListOperations操作Redis List列表&#xff0c;使用HashOperations操作Redis Hash哈希散列&#xff0c;使用SetO…...

4月软件测试面试太难,吃透这份软件测试面试笔记后,成功跳槽涨薪30K

4 月开始&#xff0c;生活工作渐渐步入正轨&#xff0c;但金三银四却没有往年顺利。昨天跟一位高级架构师的前辈聊天时&#xff0c;聊到今年的面试。有两个感受&#xff0c;一个是今年面邀的次数比往年要低不少&#xff0c;再一个就是很多面试者准备明显不足。不少候选人能力其…...

人人拥有ChatGPT的时代来临了,这次微软很大方!

技术迭代的在一段时间内是均匀发展甚至止步不前的&#xff0c;但在某段时间内会指数级别的爆发。 ChatGPT背后的GPT 3.5训练据说花了几百万美金外加几个月的时间&#xff0c;参数大概有1700多亿。 这对于绝大多数的个人或企业来说绝对是太过昂贵的。 然而&#xff0c;微软&am…...

【C++11】自动类型推导(Type Inference)

C11 中的自动类型推导是通过 auto 关键字实现的。auto 关键字可以用于声明变量&#xff0c;让编译器自动推导变量的类型。具体来说&#xff0c;编译器会根据变量的初始化表达式来推导变量的类型。 例如&#xff0c;下面的代码中&#xff0c;变量 x 的类型会被推导为 int 类型&…...

拐点!智能座舱破局2023

“这是我们看到的整个座舱域控渗透率&#xff0c;2022年是8.28%&#xff0c;主力的搭载车型仍然是30-35万区间。”3月29日&#xff0c;2023年度&#xff08;第五届&#xff09;高工智能汽车市场峰会上&#xff0c;高工智能汽车研究院首发《2022-2025年中国智能汽车产业链市场数…...

SAP开发环境ABAP的搭建(客户端和服务器),Developer Key和AccessKey的绕过方法

目录 一.前言 二.客户端GUI安装 1.下载好SAP GUI 750 2.解压后找到SAPGUISetup.exe 3.安装 4.安装完整教程 三.服务端搭建 1.安装VmWare虚拟机 2.下载虚拟机镜像 3.打开虚拟机 4.调整内存大小 5.启动虚拟机 四.创建程序 1.创建包 2.创建程序 3.Developer Key和A…...

VSCode的C/C++编译调试环境搭建(亲测有效)

文章目录前言1.安装VSCode和mingw642.配置环境变量3.配置VSCode的运行环境3.1设置CodeRunner3.2设置C/C4.调试环境配置前言 这片博客挺早前就写好了&#xff0c;一直忘记发了&#xff0c;写这篇博客之前自己配的时候也试过很多博客&#xff0c;但无一例外&#xff0c;都各种js…...

物理世界的互动之旅:Matter.js入门指南

theme: smartblue 本文简介 戴尬猴&#xff0c;我是德育处主任 欢迎来到《物理世界的互动之旅&#xff1a;Matter.js入门指南》。 本文将带您探索 Matter.js&#xff0c;一个强大而易于使用的 JavaScript 物理引擎库。 我将介绍 Matter.js 的基本概念&#xff0c;包括引擎、世界…...

在线文章生成器-文章生成器在线生成

免费自动写作软件 目前市面上存在一些免费自动写作软件&#xff0c;以下介绍几个开源的自动写作软件。 GPT-2&#xff1a;这是由OpenAI推出的一款自动写作工具&#xff0c;它可以生成高质量的文章&#xff0c;其优点在于能够理解语言结构和语法规则&#xff0c;从而生成表达自…...

第十四届蓝桥杯大赛软件赛省赛-试题 B---01 串的熵 解题思路+完整代码

欢迎访问个人网站来查看此文章&#xff1a;http://www.ghost-him.com/posts/db23c395/ 问题描述 对于一个长度为 n 的 01 串 Sx1x2x3...xnS x_{1} x_{2} x_{3} ... x_{n}Sx1​x2​x3​...xn​&#xff0c;香农信息熵的定义为 H(S)−∑1np(xi)log2(p(xi))H(S ) − {\textstyl…...

【Leetcode】消失的数字 [C语言实现]

&#x1f47b;内容专栏&#xff1a;《Leetcode刷题专栏》 &#x1f428;本文概括&#xff1a; 面试17.04.消失的数字 &#x1f43c;本文作者&#xff1a;花 碟 &#x1f438;发布时间&#xff1a;2023.4.10 目录 思想1&#xff1a;先排序再查找 思想2&#xff1a;异或运算 代…...

SpringBoot接口 - 如何实现接口限流之单实例

在以SpringBoot开发Restful接口时&#xff0c;当流量超过服务极限能力时&#xff0c;系统可能会出现卡死、崩溃的情况&#xff0c;所以就有了降级和限流。在接口层如何做限流呢&#xff1f; 本文主要回顾限流的知识点&#xff0c;并实践单实例限流的一种思路。 SpringBoot接口 …...

【花雕学AI】深度挖掘ChatGPT角色扮演的一个案例—CHARACTER play : 莎士比亚

CHARACTER play : 莎士比亚 : 52岁&#xff0c;男性&#xff0c;剧作家&#xff0c;诗人&#xff0c;喜欢文学&#xff0c;戏剧&#xff0c;爱情 : 1、问他为什么写《罗密欧与朱丽叶》 AI: 你好&#xff0c;我是莎士比亚&#xff0c;一位英国的剧作家和诗人。我很高兴你对我的…...

腾讯云物联网开发平台 LoRaWAN 透传接入 更新版

前言 之前有一篇文章介绍LoRaWAN透传数据&#xff0c;不过还是用物模型云端数据解析脚本&#xff0c;不是真正的透传。腾讯云物联网开发平台也支持对LoRaWAN原始数据的透传、转发。今天来介绍下。腾讯云 IoT Explorer 是腾讯云主推的一站式物联网开发平台&#xff0c;IoT 小能手…...

4.6--计算机网络之TCP篇之TCP的基本认识--(复习+深入)---好好沉淀,加油呀

1.TCP 头格式有哪些&#xff1f; 序列号&#xff1a; 在建立连接时由计算机生成的随机数作为其初始值&#xff0c;通过 SYN 包传给接收端主机&#xff0c;每发送一次数据&#xff0c;就「累加」一次该「数据字节数」的大小。 用来解决网络包乱序问题。 确认应答号&#xff1a; …...

一文吃透Elasticsearch

本文已经收录到Github仓库&#xff0c;该仓库包含计算机基础、Java基础、多线程、JVM、数据库、Redis、Spring、Mybatis、SpringMVC、SpringBoot、分布式、微服务、设计模式、架构、校招社招分享等核心知识点&#xff0c;欢迎star~ Github地址 如果访问不了Github&#xff0c…...

CPU占用率高怎么办?正确解决方法在这里!

案例&#xff1a;CPU占用率高怎么解决 【各位朋友&#xff0c;我的电脑现在运行太慢了&#xff0c;同事说可能是CPU占用率太高了&#xff0c;但对本电脑小白来说&#xff0c;完全不知道怎么处理&#xff0c;大家有什么好的方法可以解决这个问题吗&#xff1f;】 在计算机中&a…...

ChatGPT实现用C语言写一个学生成绩管理系统

随着ChatGPT爆火&#xff0c;大家都在使用ChatGPT来帮助自己提高效率&#xff0c;对于程序员来说使用它来写代码怎么样呢&#xff1f;今天尝试让ChatGPT&#xff0c;写了一个学生成绩管理系统。 问题是&#xff1a;使用C语言写一个学生成绩管理系统&#xff0c;要求使用链表&a…...

Swagger文档注释

本文以DRF框架为例使用 为什么要接口文档注释 一. 方便后端调试与后续接口更新&#xff1b; 二. 对于大型前后端分离项目&#xff0c;前后端人员是分开开发的&#xff0c;甚至前端的人你都不知道远在何处&#xff0c;这时候接口文档的重要性就太重要了。 三. 接口注释文档常用…...

pdf怎么转换ppt格式,两个方法转换

PDF作为一种常用的文件格式&#xff0c;被大众所熟悉。虽然PDF具备的稳定性&#xff0c;安全性&#xff0c;以及很强的兼容性可以让我们更方便顺畅的阅读PDF文件&#xff0c;但若是有需要展示PDF文件内容的时候&#xff0c;其优点就没有那么凸显了&#xff0c;这时还是将pdf转换…...

【位运算】消失的两个数字(hard)

消失的两个数字&#xff08;hard&#xff09; 题⽬描述&#xff1a;解法&#xff08;位运算&#xff09;&#xff1a;Java 算法代码&#xff1a;更简便代码 题⽬链接&#xff1a;⾯试题 17.19. 消失的两个数字 题⽬描述&#xff1a; 给定⼀个数组&#xff0c;包含从 1 到 N 所有…...

STM32F4基本定时器使用和原理详解

STM32F4基本定时器使用和原理详解 前言如何确定定时器挂载在哪条时钟线上配置及使用方法参数配置PrescalerCounter ModeCounter Periodauto-reload preloadTrigger Event Selection 中断配置生成的代码及使用方法初始化代码基本定时器触发DCA或者ADC的代码讲解中断代码定时启动…...

【2025年】解决Burpsuite抓不到https包的问题

环境&#xff1a;windows11 burpsuite:2025.5 在抓取https网站时&#xff0c;burpsuite抓取不到https数据包&#xff0c;只显示&#xff1a; 解决该问题只需如下三个步骤&#xff1a; 1、浏览器中访问 http://burp 2、下载 CA certificate 证书 3、在设置--隐私与安全--…...

Springcloud:Eureka 高可用集群搭建实战(服务注册与发现的底层原理与避坑指南)

引言&#xff1a;为什么 Eureka 依然是存量系统的核心&#xff1f; 尽管 Nacos 等新注册中心崛起&#xff0c;但金融、电力等保守行业仍有大量系统运行在 Eureka 上。理解其高可用设计与自我保护机制&#xff0c;是保障分布式系统稳定的必修课。本文将手把手带你搭建生产级 Eur…...

【Oracle】分区表

个人主页&#xff1a;Guiat 归属专栏&#xff1a;Oracle 文章目录 1. 分区表基础概述1.1 分区表的概念与优势1.2 分区类型概览1.3 分区表的工作原理 2. 范围分区 (RANGE Partitioning)2.1 基础范围分区2.1.1 按日期范围分区2.1.2 按数值范围分区 2.2 间隔分区 (INTERVAL Partit…...

鸿蒙DevEco Studio HarmonyOS 5跑酷小游戏实现指南

1. 项目概述 本跑酷小游戏基于鸿蒙HarmonyOS 5开发&#xff0c;使用DevEco Studio作为开发工具&#xff0c;采用Java语言实现&#xff0c;包含角色控制、障碍物生成和分数计算系统。 2. 项目结构 /src/main/java/com/example/runner/├── MainAbilitySlice.java // 主界…...

Golang——7、包与接口详解

包与接口详解 1、Golang包详解1.1、Golang中包的定义和介绍1.2、Golang包管理工具go mod1.3、Golang中自定义包1.4、Golang中使用第三包1.5、init函数 2、接口详解2.1、接口的定义2.2、空接口2.3、类型断言2.4、结构体值接收者和指针接收者实现接口的区别2.5、一个结构体实现多…...

通过 Ansible 在 Windows 2022 上安装 IIS Web 服务器

拓扑结构 这是一个用于通过 Ansible 部署 IIS Web 服务器的实验室拓扑。 前提条件&#xff1a; 在被管理的节点上安装WinRm 准备一张自签名的证书 开放防火墙入站tcp 5985 5986端口 准备自签名证书 PS C:\Users\azureuser> $cert New-SelfSignedCertificate -DnsName &…...

go 里面的指针

指针 在 Go 中&#xff0c;指针&#xff08;pointer&#xff09;是一个变量的内存地址&#xff0c;就像 C 语言那样&#xff1a; a : 10 p : &a // p 是一个指向 a 的指针 fmt.Println(*p) // 输出 10&#xff0c;通过指针解引用• &a 表示获取变量 a 的地址 p 表示…...

渗透实战PortSwigger靶场:lab13存储型DOM XSS详解

进来是需要留言的&#xff0c;先用做简单的 html 标签测试 发现面的</h1>不见了 数据包中找到了一个loadCommentsWithVulnerableEscapeHtml.js 他是把用户输入的<>进行 html 编码&#xff0c;输入的<>当成字符串处理回显到页面中&#xff0c;看来只是把用户输…...