SpringBoot整合Redis完整篇

SpringBoot整合Redis完整篇

1、在springboot項目的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.4.5</version><relativePath/></parent><groupId>com.example</groupId><artifactId>spring-boot-redis</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-boot-redis</name><description>spring-boot-redis</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2、在application.properties中配置redis參數

# Redis數據庫索引(默認為0)
spring.redis.database=0
# Redis服務器地址
spring.redis.host=127.0.0.1
# Redis服務器連接端口
spring.redis.port=6379
# Redis服務器連接密碼(默認為空)
spring.redis.password=
# 連接池最大連接數(使用負值表示沒有限制)
spring.redis.jedis.pool.max-active=10
# 連接池最大阻塞等待時間(使用負值表示沒有限制)
spring.redis.jedis.pool.max-wait=-1ms
# 連接池中的最大空閑連接
spring.redis.jedis.pool.max-idle=10
# 連接池中的最小空閑連接
spring.redis.jedis.pool.min-idle=0
# 連接超時時間(毫秒)
spring.redis.timeout=1000ms

3、Redis的配置類

Spring 封裝了RedisTemplate<K,V>對象來操作redis。

Spring在org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration類下配置的兩

RedisTemplate的Bean。

RedisTemplate<Object, Object>

這個Bean使用JdkSerializationRedisSerializer進行序列化,即key, value需要實現Serializable接口,

redis數據格式比較難懂。

StringRedisTemplate,即RedisTemplate<String, String>

key和value都是String。當需要存儲實體類時,需要先轉為String,再存入Redis。一般轉為Json格式的字符串,所

以使用StringRedisTemplate,需要手動將實體類轉為Json格式。

ValueOperations<String, String> valueTemplate = stringTemplate.opsForValue();
Gson gson = new Gson();valueTemplate.set("StringKey1", "hello spring boot redis, String Redis");
String value = valueTemplate.get("StringKey1");
System.out.println(value);valueTemplate.set("StringKey2", gson.toJson(new Person("theName", 11)));
Person person = gson.fromJson(valueTemplate.get("StringKey2"), Person.class);
System.out.println(person);

Spring配置的兩個RedisTemplate都不太方便使用,所以可以配置一個RedisTemplate<String,Object>

Bean,key使用String即可(包括Redis Hash 的key),value存取Redis時默認使用Json格式轉換。

package com.example.springbootredisuse1.config;import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;import java.net.UnknownHostException;/*** @author zhangshixing* @date 2021年11月06日 9:44* redis 配置類*/
@Configuration
public class RedisConfig {@Bean@ConditionalOnMissingBean(name = "redisTemplate")public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory)throws UnknownHostException {// 定義Jackson2JsonRedisSerializer序列化對象Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);ObjectMapper om = new ObjectMapper();// 指定要序列化的域,field,get和set,以及修飾符范圍,ANY是都有包括private和publicom.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);// 指定序列化輸入的類型,類必須是非final修飾的,final修飾的類,比如String,Integer等會報異常om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);jackson2JsonRedisSerializer.setObjectMapper(om);// 創建RedisTemplate<String, Object>對象RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();// 配置連接工廠template.setConnectionFactory(redisConnectionFactory);StringRedisSerializer stringSerial = new StringRedisSerializer();// redis key 序列化方式使用stringSerialtemplate.setKeySerializer(stringSerial);// redis value 序列化方式使用jacksontemplate.setValueSerializer(jackson2JsonRedisSerializer);// redis hash key 序列化方式使用stringSerialtemplate.setHashKeySerializer(stringSerial);// redis hash value 序列化方式使用jacksontemplate.setHashValueSerializer(jackson2JsonRedisSerializer);template.afterPropertiesSet();return template;}
}

4、Redis的工具類

package com.example.springbootredisuse1.utils;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;/*** @author zhangshixing* @date 2021年11月06日 9:46* redis 工具類*/
@Component
public class RedisUtils {/*** 日志對象*/private static Logger logger = LoggerFactory.getLogger(RedisUtils.class);@Autowiredprivate RedisTemplate<String, Object> redisTemplate;/*** 指定緩存失效時間** @param key  鍵* @param time 時間(秒)* @return*/public boolean expire(String key, long time) {try {if (time > 0) {redisTemplate.expire(key, time, TimeUnit.SECONDS);}return true;} catch (Exception e) {logger.error("RedisUtils expire(String key,long time) failure." + e.getMessage());return false;}}/*** 根據key 獲取過期時間** @param key 鍵 不能為null* @return 時間(秒) 返回0代表為永久有效*/public long getExpire(String key) {return redisTemplate.getExpire(key, TimeUnit.SECONDS);}/*** 判斷key是否存在** @param key 鍵* @return true 存在 false不存在*/public boolean hasKey(String key) {try {return redisTemplate.hasKey(key);} catch (Exception e) {logger.error("RedisUtils hasKey(String key) failure." + e.getMessage());return false;}}/*** 刪除緩存** @param key 可以傳一個值 或多個*/@SuppressWarnings("unchecked")public void del(String... key) {if (key != null && key.length > 0) {if (key.length == 1) {redisTemplate.delete(key[0]);} else {redisTemplate.delete((Collection<String>) CollectionUtils.arrayToList(key));}}}/*** 普通緩存獲取** @param key 鍵* @return 值*/public Object get(String key) {System.out.println(key);return key == null ? null : redisTemplate.opsForValue().get(key);}/*** 普通緩存放入** @param key   鍵* @param value 值* @return true成功 false失敗*/public boolean set(String key, Object value) {try {redisTemplate.opsForValue().set(key, value);return true;} catch (Exception e) {logger.error("RedisUtils set(String key,Object value) failure." + e.getMessage());return false;}}/*** 普通緩存放入并設置時間** @param key   鍵* @param value 值* @param time  時間(秒) time要大于0 如果time小于等于0 將設置無限期* @return true成功 false 失敗*/public boolean set(String key, Object value, long time) {try {if (time > 0) {redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);} else {set(key, value);}return true;} catch (Exception e) {logger.error("RedisUtils set(String key,Object value,long time) failure." + e.getMessage());return false;}}/*** 遞增** @param key   鍵* @param delta* @return*/public long incr(String key, long delta) {if (delta < 0) {throw new RuntimeException("遞增因子必須大于0");}return redisTemplate.opsForValue().increment(key, delta);}/*** 遞減** @param key   鍵* @param delta 要減少幾(小于0)* @return*/public long decr(String key, long delta) {if (delta < 0) {throw new RuntimeException("遞減因子必須大于0");}return redisTemplate.opsForValue().increment(key, -delta);}/*** HashGet** @param key  鍵 不能為null* @param item 項 不能為null* @return 值*/public Object hget(String key, String item) {return redisTemplate.opsForHash().get(key, item);}/*** 獲取hashKey對應的所有鍵值** @param key 鍵* @return 對應的多個鍵值*/public Map<Object, Object> hmget(String key) {return redisTemplate.opsForHash().entries(key);}/*** HashSet** @param key 鍵* @param map 對應多個鍵值* @return true 成功 false 失敗*/public boolean hmset(String key, Map<String, Object> map) {try {redisTemplate.opsForHash().putAll(key, map);return true;} catch (Exception e) {logger.error("RedisUtils hmset(String key, Map<String,Object> map) failure." + e.getMessage());return false;}}/*** HashSet 并設置時間** @param key  鍵* @param map  對應多個鍵值* @param time 時間(秒)* @return true成功 false失敗*/public boolean hmset(String key, Map<String, Object> map, long time) {try {redisTemplate.opsForHash().putAll(key, map);if (time > 0) {expire(key, time);}return true;} catch (Exception e) {logger.error("RedisUtils hmset(String key, Map<String,Object> map, long time) failure." + e.getMessage());return false;}}/*** 向一張hash表中放入數據,如果不存在將創建** @param key   鍵* @param item  項* @param value 值* @return true 成功 false失敗*/public boolean hset(String key, String item, Object value) {try {redisTemplate.opsForHash().put(key, item, value);return true;} catch (Exception e) {logger.error("RedisUtils hset(String key,String item,Object value) failure." + e.getMessage());return false;}}/*** 向一張hash表中放入數據,如果不存在將創建** @param key   鍵* @param item  項* @param value 值* @param time  時間(秒)  注意:如果已存在的hash表有時間,這里將會替換原有的時間* @return true 成功 false失敗*/public boolean hset(String key, String item, Object value, long time) {try {redisTemplate.opsForHash().put(key, item, value);if (time > 0) {expire(key, time);}return true;} catch (Exception e) {logger.error("RedisUtils hset(String key,String item,Object value,long time) failure." + e.getMessage());return false;}}/*** 刪除hash表中的值** @param key  鍵 不能為null* @param item 項 可以使多個 不能為null*/public void hdel(String key, Object... item) {redisTemplate.opsForHash().delete(key, item);}/*** 判斷hash表中是否有該項的值** @param key  鍵 不能為null* @param item 項 不能為null* @return true 存在 false不存在*/public boolean hHasKey(String key, String item) {return redisTemplate.opsForHash().hasKey(key, item);}/*** hash遞增 如果不存在,就會創建一個 并把新增后的值返回** @param key  鍵* @param item 項* @param by   要增加幾(大于0)* @return*/public double hincr(String key, String item, double by) {return redisTemplate.opsForHash().increment(key, item, by);}/*** hash遞減** @param key  鍵* @param item 項* @param by   要減少記(小于0)* @return*/public double hdecr(String key, String item, double by) {return redisTemplate.opsForHash().increment(key, item, -by);}/*** 根據key獲取Set中的所有值** @param key 鍵* @return*/public Set<Object> sGet(String key) {try {return redisTemplate.opsForSet().members(key);} catch (Exception e) {logger.error("RedisUtils sGet(String key) failure." + e.getMessage());return null;}}/*** 根據value從一個set中查詢,是否存在** @param key   鍵* @param value 值* @return true 存在 false不存在*/public boolean sHasKey(String key, Object value) {try {return redisTemplate.opsForSet().isMember(key, value);} catch (Exception e) {logger.error("RedisUtils sHasKey(String key,Object value) failure." + e.getMessage());return false;}}/*** 將數據放入set緩存** @param key    鍵* @param values 值 可以是多個* @return 成功個數*/public long sSet(String key, Object... values) {try {return redisTemplate.opsForSet().add(key, values);} catch (Exception e) {logger.error("RedisUtils sSet(String key, Object...values) failure." + e.getMessage());return 0;}}/*** 將set數據放入緩存** @param key    鍵* @param time   時間(秒)* @param values 值 可以是多個* @return 成功個數*/public long sSetAndTime(String key, long time, Object... values) {try {Long count = redisTemplate.opsForSet().add(key, values);if (time > 0) {expire(key, time);}return count;} catch (Exception e) {logger.error("RedisUtils sSetAndTime(String key,long time,Object...values) failure." + e.getMessage());return 0;}}/*** 獲取set緩存的長度** @param key 鍵* @return*/public long sGetSetSize(String key) {try {return redisTemplate.opsForSet().size(key);} catch (Exception e) {logger.error("RedisUtils sGetSetSize(String key) failure." + e.getMessage());return 0;}}/*** 移除值為value的** @param key    鍵* @param values 值 可以是多個* @return 移除的個數*/public long setRemove(String key, Object... values) {try {Long count = redisTemplate.opsForSet().remove(key, values);return count;} catch (Exception e) {logger.error("RedisUtils setRemove(String key, Object ...values) failure." + e.getMessage());return 0;}}/*** 獲取list緩存的內容** @param key   鍵* @param start 開始* @param end   結束  0 到 -1代表所有值* @return*/public List<Object> lGet(String key, long start, long end) {try {return redisTemplate.opsForList().range(key, start, end);} catch (Exception e) {logger.error("RedisUtils lGet(String key, long start, long end) failure." + e.getMessage());return null;}}/*** 獲取list緩存的長度** @param key 鍵* @return*/public long lGetListSize(String key) {try {return redisTemplate.opsForList().size(key);} catch (Exception e) {logger.error("RedisUtils lGetListSize(String key) failure." + e.getMessage());return 0;}}/*** 通過索引 獲取list中的值** @param key   鍵* @param index 索引  index>=0時, 0 表頭,1 第二個元素,依次類推;index<0時,-1,表尾,-2倒數第二個元素,依次類推* @return*/public Object lGetIndex(String key, long index) {try {return redisTemplate.opsForList().index(key, index);} catch (Exception e) {logger.error("RedisUtils lGetIndex(String key,long index) failure." + e.getMessage());return null;}}/*** 將list放入緩存** @param key   鍵* @param value 值* @return*/public boolean lSet(String key, Object value) {try {redisTemplate.opsForList().rightPush(key, value);return true;} catch (Exception e) {logger.error("RedisUtils lSet(String key, Object value) failure." + e.getMessage());return false;}}/*** 將list放入緩存** @param key   鍵* @param value 值* @param time  時間(秒)* @return*/public boolean lSet(String key, Object value, long time) {try {redisTemplate.opsForList().rightPush(key, value);if (time > 0) {expire(key, time);}return true;} catch (Exception e) {logger.error("RedisUtils lSet(String key, Object value, long time) failure." + e.getMessage());return false;}}/*** 將list放入緩存** @param key   鍵* @param value 值* @return*/public boolean lSet(String key, List<Object> value) {try {redisTemplate.opsForList().rightPushAll(key, value);return true;} catch (Exception e) {logger.error("RedisUtils lSet(String key, List<Object> value) failure." + e.getMessage());return false;}}/*** 將list放入緩存** @param key   鍵* @param value 值* @param time  時間(秒)* @return*/public boolean lSet(String key, List<Object> value, long time) {try {redisTemplate.opsForList().rightPushAll(key, value);if (time > 0) {expire(key, time);}return true;} catch (Exception e) {logger.error("RedisUtils lSet(String key, List<Object> value, long time) failure." + e.getMessage());return false;}}/*** 根據索引修改list中的某條數據** @param key   鍵* @param index 索引* @param value 值* @return*/public boolean lUpdateIndex(String key, long index, Object value) {try {redisTemplate.opsForList().set(key, index, value);return true;} catch (Exception e) {logger.error("RedisUtils lUpdateIndex(String key, long index,Object value) failure." + e.getMessage());return false;}}/*** 移除N個值為value** @param key   鍵* @param count 移除多少個* @param value 值* @return 移除的個數*/public long lRemove(String key, long count, Object value) {try {Long remove = redisTemplate.opsForList().remove(key, count, value);return remove;} catch (Exception e) {logger.error("RedisUtils lRemove(String key,long count,Object value) failure." + e.getMessage());return 0;}}
}

5、RedisController

package com.example.springbootredisuse1.controller;import com.example.springbootredisuse1.utils.RedisUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;/*** @author zhangshixing* @date 2021年11月07日 10:23*/
@RequestMapping("/redis")
@RestController
public class RedisController {// redis中存儲的過期時間60sprivate static int ExpireTime = 60;@Resourceprivate RedisUtils redisUtil;@RequestMapping("set")public boolean redisset(String key, String value) {return redisUtil.set(key, value);}@RequestMapping("get")public Object redisget(String key) {return redisUtil.get(key);}@RequestMapping("expire")public boolean expire(String key) {return redisUtil.expire(key, ExpireTime);}
}

6、啟動類

package com.example.springbootredisuse1;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringBootRedisApplication {public static void main(String[] args) {SpringApplication.run(SpringBootRedisApplication.class, args);}}

7、測試

用的Postman工具測試,也可以用瀏覽器或其他工具測試。

1.添加鍵值

在這里插入圖片描述

返回:true 代表向redis中存成功

2.獲取鍵值

在這里插入圖片描述

3.設置過期時間

在這里插入圖片描述

過期時間為60s,60s后再次查詢:
在這里插入圖片描述

發現該鍵已經過期,值為空。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/40028.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/40028.shtml
英文地址,請注明出處:http://en.pswp.cn/news/40028.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

分布式鎖有哪些應用場景和實現?

電商網站都會遇到秒殺、特價之類的活動&#xff0c;大促活動有一個共同特點就是訪問量激增&#xff0c;在高并發下會出現成千上萬人搶購一個商品的場景。雖然在系統設計時會通過限流、異步、排隊等方式優化&#xff0c;但整體的并發還是平時的數倍以上&#xff0c;參加活動的商…

WebRTC音視頻通話-實現GPUImage視頻美顏濾鏡效果iOS

WebRTC音視頻通話-實現GPUImage視頻美顏濾鏡效果 在WebRTC音視頻通話的GPUImage美顏效果圖如下 可以看下 之前搭建ossrs服務&#xff0c;可以查看&#xff1a;https://blog.csdn.net/gloryFlow/article/details/132257196 之前實現iOS端調用ossrs音視頻通話&#xff0c;可以查…

2023秋招筆試

檸檬微趣 將java的鏈表升序排序&#xff0c;鏈表用Class Node{int val,Node next}實現 import java.util.Comparator; import java.util.PriorityQueue; import java.util.Scanner;/*** 輸入一串數字&#xff0c;放入list中&#xff0c;實現sortList&#xff0c;返回升序的li…

將單個訓練數據集文件拆分為:image文件和label文件(pytorch學習+螞蟻蜜蜂數據集)

螞蟻蜜蜂分類數據集下載鏈接&#xff1a;https://download.pytorch.org/tutorial/hymenoptera_data.zip 要實現如圖操作&#xff1a; 將ants分為ants_image和ants_label 將bees分成bees_image和bees_label 創建ants_label和bees_label&#xff0c;并且以圖片名作為txt文件的…

Apche Kafka + Spring的消息監聽容器

目錄 一、消息的接收1.1、消息監聽器 二、消息監聽容器2.1、 實現方法2.1.1、KafkaMessageListenerContainer2.1.1.1、 基本概念2.1.1.2、如何使用 KafkaMessageListenerContainer 2.1.2、ConcurrentMessageListenerContainer 三、偏移 四、監聽器容器自動啟動 一、消息的接收 …

【機器學習】sklearn數據集的使用,數據集的獲取和劃分

「作者主頁」&#xff1a;士別三日wyx 「作者簡介」&#xff1a;CSDN top100、阿里云博客專家、華為云享專家、網絡安全領域優質創作者 「推薦專欄」&#xff1a;對網絡安全感興趣的小伙伴可以關注專欄《網絡安全入門到精通》 sklearn數據集 二、安裝sklearn二、獲取數據集三、…

mac錄屏工具,錄屏沒有聲音的解決辦法

mac錄屏工具&#xff0c;錄屏沒有聲音的解決辦法 在使用macbook錄制屏幕時&#xff0c;發現自帶的錄屏工具QuickTime Player沒有聲音&#xff0c;于是嘗試了多款錄屏工具&#xff0c;對其做一些經驗總結&#xff08;省流&#xff1a;APP Store直接可以免費下載使用Omi錄屏專家…

第三課-界面介紹SD-Stable Diffusion 教程

前言 我們已經安裝好了SD&#xff0c;這篇文章不介紹難以理解的原理&#xff0c;說使用。以后再介紹原理。 我的想法是&#xff0c;先學會畫&#xff0c;然后明白原理&#xff0c;再去提高技術。 我失敗過&#xff0c;知道三天打魚兩天曬網的痛苦&#xff0c;和很多人一樣試了…

TiDB數據庫從入門到精通系列之六:使用 TiCDC 將 TiDB 的數據同步到 Apache Kafka

TiDB數據庫從入門到精通系列之六&#xff1a;使用 TiCDC 將 TiDB 的數據同步到 Apache Kafka 一、技術流程二、搭建環境三、創建Kafka changefeed四、寫入數據以產生變更日志五、配置 Flink 消費 Kafka 數據 一、技術流程 快速搭建 TiCDC 集群、Kafka 集群和 Flink 集群創建 c…

【網絡編程系列】網絡編程實戰

&#x1f49d;&#x1f49d;&#x1f49d;歡迎來到我的博客&#xff0c;很高興能夠在這里和您見面&#xff01;希望您在這里可以感受到一份輕松愉快的氛圍&#xff0c;不僅可以獲得有趣的內容和知識&#xff0c;也可以暢所欲言、分享您的想法和見解。 推薦:kuan 的首頁,持續學…

使用Vue.js框架的指令和事件綁定實現一個購物車的頁面布局

使用了v-model指令來實現全選/全不選的功能&#xff0c;當全選框被點擊時&#xff0c;isAllChecked的值會被改變。使用了v-if指令來判斷購物車中是否有商品&#xff0c;如果有商品則渲染商品列表&#xff0c;否則顯示購物車為空的提示。使用了v-for指令來遍歷datalist數組&…

jvm內存溢出排查(使用idea自帶的內存泄漏分析工具)

文章目錄 1.確保生成內存溢出文件2.使用idea自帶的內存泄漏分析工具3.具體實驗一下 1.確保生成內存溢出文件 想分析堆內存溢出&#xff0c;一定在運行jar包時就寫上參數-XX:HeapDumpOnOutOfMemoryError&#xff0c;可以看我之前關于如何運行jar包的文章。若你沒有寫。可以寫上…

Keepalived入門指南:實現故障轉移和負載均衡

文章目錄 一、簡介1. Keepalived概述2. 高可用性和負載均衡的重要性 二、故障轉移1. 什么是故障轉移2. Keepalived的故障轉移原理a) VRRP協議b) 虛擬路由器ID和優先級 3. 配置Keepalived實現故障轉移a) 主備服務器的設置b) 監控網絡接口c) 虛擬IP的配置d) 備份服務器接管流程 三…

Python學習筆記_基礎篇(九)_面向對象編程

本篇內容: 1、反射2、面向對象編程3、面向對象三大特性4、類成員5、類成員修飾符6、類的特殊成員7、單例模式 反射 python中的反射功能是由以下四個內置函數提供&#xff1a;hasattr、getattr、setattr、delattr&#xff0c;改四個函數分別用于對對象內部執行&#xff1a;檢…

el-form自定義校驗規則

Vue 的 el-form 組件可以使用自定義校驗規則進行表單驗證。自定義校驗規則可以通過傳遞一個函數來實現&#xff0c;該函數接受要校驗的字段的值作為參數&#xff0c;并返回一個布爾值或一個 Promise 對象。 下面是一個示例&#xff0c;演示如何在 el-form 中使用自定義校驗規則…

若依前端npm run dev啟動時報錯

本文主要解決問題:若依前端npm run dev啟動時報錯,解決辦法。 目錄 1、第1種解決方案(親測有效) 2、第2種解決方案(親測有效) Error: error:0308010C:digital envelope routines::unsupportedat new Hash (node:internal/crypto/hash:67:19)at Object.createHash (node…

解決 adb install 錯誤INSTALL_FAILED_UPDATE_INCOMPATIBLE

最近給游戲出包&#xff0c;平臺要求 v1 簽名吧&#xff0c;AS 打包后&#xff0c;adb 執行安裝到手機&#xff0c;我用的設備是google pixel6 , android 系統 13&#xff0c; 提示如下&#xff1a; adb install -r v5_android_202308161046.apk Performing Streamed Install a…

centos 安裝.net 6 sdk

按照以下步驟在 CentOS 上安裝 .NET 6 SDK&#xff1a; 更新系統&#xff1a; sudo yum update安裝依賴項&#xff1a; sudo yum install -y curl libunwind libicu下載并添加 Microsoft 的軟件包存儲庫密鑰&#xff1a; sudo rpm -Uvh https://packages.microsoft.com/config/…

單片機第一季:零基礎13——AD和DA轉換

1&#xff0c;AD轉換基本概念 51 單片機系統內部運算時用的全部是數字量&#xff0c;即0 和1&#xff0c;因此對單片機系統而言&#xff0c;無法直接操作模擬量&#xff0c;必須將模擬量轉換成數字量。所謂數字量&#xff0c;就是用一系列0 和1 組成的二進制代碼表示某個信號大…

Linux -- 進階 Autofs自動掛載服務 實驗詳解

服務端創建共享目錄&#xff0c; 客戶端實現自動掛載 第一步 &#xff1a; 客戶端&#xff0c;服務端 均關閉安全軟件 [rootserver ~]# setenforce 0 [rootserver ~]# systemctl stop firewalld [rootnode1 ~]# setenforce 0 [rootnode1 ~]# systemctl stop firewalld 第二…