中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

怎樣做網(wǎng)站手機和電腦通用汕頭seo排名公司

怎樣做網(wǎng)站手機和電腦通用,汕頭seo排名公司,做網(wǎng)站在哪接廣告,韶關(guān)做網(wǎng)站公司布隆過濾器&#xff08;Bloom Filter&#xff09;是一種高效的概率型數(shù)據(jù)結(jié)構(gòu)&#xff0c;用于判斷一個元素是否屬于一個集合。它通過使用哈希函數(shù)和位數(shù)組來存儲和查詢數(shù)據(jù)&#xff0c;具有較快的插入和查詢速度&#xff0c;并且占用空間相對較少。 引入依賴 <!--切面--&…

布隆過濾器(Bloom Filter)是一種高效的概率型數(shù)據(jù)結(jié)構(gòu),用于判斷一個元素是否屬于一個集合。它通過使用哈希函數(shù)和位數(shù)組來存儲和查詢數(shù)據(jù),具有較快的插入和查詢速度,并且占用空間相對較少。

引入依賴

<!--切面-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency><!-- 數(shù)據(jù)庫-->
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql.version}</version>
</dependency>
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.1</version>
</dependency>

properties配置

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/itcast?serverTimezone=GMT%2B8&useUnicode=true&logger=Slf4JLogger&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=root123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.hikari.pool-name=HikariCPDatasource
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=180000
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1
mybatis-plus.configuration.log-impl= org.apache.ibatis.logging.stdout.StdOutImpl
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.redis.timeout=10s
spring.redis.password=123

自定義注解


import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;/*** 此注解可作用于控制器方法,或者服務(wù)類方法** 使用示例,在目標(biāo)方法上添加如下注解* <pre>*     BitMap(key = "user", id = "#id")* </pre>**/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface BitMap {/*** <p>同一類集合的唯一標(biāo)識符 商品表、訂單表分別設(shè)置不同key</p>*/String key();/*** 支持{@code SPEL}表達式* 含義是以被調(diào)用方法參數(shù)<code>id</code>的值作為主鍵ID*/String id() default "#id";
}

切面

import com.example.demo.annotation.BitMap;
import com.example.demo.util.ParserUtils;
import com.example.demo.util.RedisBitMapUtils;
import com.example.demo.util.ResponseResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.TreeMap;/*** Redis BitMap AOP**/
@Aspect
@Component
public class BitMapAspect {private static final Logger logger = LoggerFactory.getLogger(BitMapAspect.class);@Resourceprivate RedisBitMapUtils redisBitMapUtils;@Pointcut("@annotation(com.example.demo.annotation.BitMap)")public void aspect() {}@Around("aspect()")public Object doAround(ProceedingJoinPoint point) throws Throwable {// 通過 point 對象獲取方法簽名信息。MethodSignature signature = (MethodSignature) point.getSignature();// 通過方法簽名獲取當(dāng)前方法對象。Method method = signature.getMethod();// 獲取當(dāng)前方法上的 BitMap 注解。BitMap annotation = method.getAnnotation(BitMap.class);// 獲取方法參數(shù)名和參數(shù)值的映射關(guān)系,并將結(jié)果保存到TreeMap中。TreeMap<String, Object> map = ParserUtils.createTreeMap(point, signature);// 從參數(shù)映射中獲取 id 參數(shù)對應(yīng)的值。String idString = ParserUtils.parse(annotation.id(), map);if (idString != null) {long id = Long.parseLong(idString);if (redisBitMapUtils.isPresent(annotation.key(), id)) {return point.proceed();} else {logger.info(String.format("當(dāng)前主鍵ID{%d}不存在", id));return method.getReturnType().equals(ResponseResult.class) ? ResponseResult.okResult() : null;}}throw new RuntimeException("主鍵ID解析不正確,請按照參考格式書寫");}}

RedisBitMap工具類

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;/*** {@link RedisBitMapUtils}工具類*/
@Component
public class RedisBitMapUtils {private static final Logger logger = LoggerFactory.getLogger(RedisBitMapUtils.class);@Resourceprivate   StringRedisTemplate stringRedisTemplate ;ValueOperations<String, String> opsForValue;@PostConstructpublic  void init() {opsForValue= stringRedisTemplate.opsForValue();}/*** 該方法可以方便地將一個集合中的每個元素根據(jù)給定的映射函數(shù)進行轉(zhuǎn)換,* 并返回一個新的列表。如果集合為空或為null,則返回一個空列表。* @param list* @param action* @return* @param <T>* @param <R>*/public  <T, R> List<R> toList(final Collection<T> list, final Function<? super T, ? extends R> action) {Objects.requireNonNull(action);if (Objects.nonNull(list)) {return list.stream().map(action).collect(Collectors.toList());}return Collections.emptyList();}/*** <p>本方法在首次初始化以{@code key}為參數(shù)的BitMap時執(zhí)行</p>* <p>首先刪除Key 然后重新構(gòu)建BitMap</p>** @param <T> 主鍵類型* @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param ids 主鍵ID*/public  <T extends Serializable> void init(String key, Collection<T> ids) {remove(key);setBit(key, ids);}/*** <p>本方法在首次初始化以{@code key}為參數(shù)的BitMap時執(zhí)行</p>* <p>首先刪除Key 然后重新構(gòu)建BitMap</p>** @param key    每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param list   實體類對象集合* @param action 主鍵列(方法引用表示)* @param <T>    實體類泛型* @param <R>    主鍵列泛型*/public  <T, R extends Serializable> void init(String key, Collection<T> list, Function<T, R> action) {List<R> ids = toList(list, action);init(key, ids);}/*** 檢查當(dāng)前主鍵ID在Redis BitMap中是否存在 如果存在則執(zhí)行函數(shù)式回調(diào)** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID* @return {@code R}實例*/public  <T extends Serializable, R> R ifPresent(String key, T id, Function<T, R> action) {if (getBit(key, id)) {return action.apply(id);}return null;}/*** 檢查當(dāng)前主鍵ID在Redis BitMap中是否存在 如果存在則執(zhí)行函數(shù)式回調(diào)** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID* @return {@code R}實例*/public  <T extends Serializable, R> R ifPresent(String key, T id, Supplier<R> supplier) {if (getBit(key, id)) {return supplier.get();}return null;}/*** 檢查當(dāng)前主鍵ID在Redis BitMap中是否存在 如果存在則返回<code>true</code>** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID* @return 如果存在則返回<code>true</code>*/public  <T extends Serializable> boolean isPresent(String key, T id) {return getBit(key, id);}/*** 檢查當(dāng)前主鍵ID在Redis BitMap中是否存在 如果存在則返回<code>true</code>* 本方法是{@link RedisBitMapUtils#getBit(String, Serializable)}的別名方法 方便對外調(diào)用** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID* @return 如果存在則返回<code>true</code>*/public  <T extends Serializable> boolean checkId(String key, T id) {return getBit(key, id);}/*** 檢查當(dāng)前主鍵ID(集合)在Redis BitMap中是否存在 只返回存在的主鍵ID* 本方法是{@link RedisBitMapUtils#getBit(String, Serializable)}的別名方法 方便對外調(diào)用** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param ids 主鍵ID* @return 返回存在的主鍵ID*/public  <T extends Serializable> List<T> checkIds(String key, Collection<T> ids) {return ids.stream().filter(e -> checkId(key, e)).collect(Collectors.toList());}/*** 向Redis BitMap中保存主鍵ID** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID*/public  <T extends Serializable> void setBit(String key, T id) {ifOffsetValid(Objects.hash(id), e -> opsForValue.setBit(key, e, true));}/*** 向Redis BitMap中批量保存主鍵ID** @param <T> 主鍵類型* @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param ids 主鍵ID*/public  <T extends Serializable> void setBit(String key, Collection<T> ids) {ids.forEach(id -> ifOffsetValid(Objects.hash(id), e -> opsForValue.setBit(key, e, true)));}/*** 檢查當(dāng)前主鍵ID在Redis BitMap中是否存在 如果存在則返回<code>true</code>** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID* @return 如果存在則返回<code>true</code>*/public  <T extends Serializable> boolean getBit(String key, T id) {return ifOffsetValid(Objects.hash(id), e -> opsForValue.getBit(key, e));}/*** 從Redis BitMap中刪除當(dāng)前主鍵ID** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param id  主鍵ID*/public  <T extends Serializable> void removeBit(String key, T id) {ifOffsetValid(Objects.hash(id), e -> opsForValue.setBit(key, e, false));}/*** 從Redis BitMap中批量刪除主鍵ID** @param key 每種業(yè)務(wù)分別對應(yīng)不同的Key名稱* @param ids 主鍵ID* @param <T> 主鍵類型*/public  <T extends Serializable> void removeBit(String key, Collection<T> ids) {ids.forEach(id -> ifOffsetValid(Objects.hash(id), e -> opsForValue.setBit(key, e, false)));}/*** 將當(dāng)前分類下的BitMap Key刪除* 清空該Key下所有數(shù)據(jù)*/public  void remove(String key) {stringRedisTemplate.delete(key);}/*** <p>檢查偏移量是否合法</p>* <p>Redis字符串支持字符串最大長度512M,因此支持offset的最大值為(2^32)-1</p>** @param offset 偏移量* @param action 映射規(guī)則*/private static <N extends Number> Boolean ifOffsetValid(N offset, Function<N, Boolean> action) {Objects.requireNonNull(action);//如果ID用整型表示 那么正整數(shù)范圍內(nèi)所有的ID均有效 最大正整數(shù)值為2147483647 約為20億long max = (1L << 32) - 1;if (offset.intValue() >= 0 && offset.intValue() < Integer.MAX_VALUE) {return action.apply(offset);} else {// 如果偏移量類型為長整型,或者整型范圍內(nèi)的最大值小于0且 offset 的值小于等于 maxif (Integer.MAX_VALUE >= 0 && offset.longValue() <= max) {return action.apply(offset);} else {logger.info(String.format("偏移量{%d}越界[0,%s],本次操作不成功!", offset.longValue(), max));return false;}}}
}

response工具類


import lombok.Data;import java.io.Serializable;
@Data
public class ResponseResult<T> implements Serializable {private Boolean success;private Integer code;private String msg;private T data;public ResponseResult() {this.success=true;this.code = HttpCodeEnum.SUCCESS.getCode();this.msg = HttpCodeEnum.SUCCESS.getMsg();}public ResponseResult(Integer code, T data) {this.code = code;this.data = data;}public ResponseResult(Integer code, String msg, T data) {this.code = code;this.msg = msg;this.data = data;}public ResponseResult(Integer code, String msg) {this.code = code;this.msg = msg;}public static ResponseResult errorResult(int code, String msg) {ResponseResult result = new ResponseResult();return result.error(code, msg);}public static ResponseResult okResult() {ResponseResult result = new ResponseResult();return result;}public static ResponseResult okResult(int code, String msg) {ResponseResult result = new ResponseResult();return result.ok(code, null, msg);}public static ResponseResult setHttpCodeEnum(HttpCodeEnum enums) {return okResult(enums.getCode(), enums.getMsg());}public static <T> ResponseResult<T> error(String message) {return new ResponseResult<T>(HttpCodeEnum.SYSTEM_ERROR.getCode(),  message);}public ResponseResult<?> error(Integer code, String msg) {this.success=false;this.code = code;this.msg = msg;return this;}public ResponseResult<?> ok(Integer code, T data) {this.success=true;this.code = code;this.data = data;return this;}public ResponseResult<?> ok(Integer code, T data, String msg) {this.success=true;this.code = code;this.data = data;this.msg = msg;return this;}public static ResponseResult ok(Object data) {ResponseResult result = new ResponseResult();result.setData(data);return result;}}

controller


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.annotation.BitMap;
import com.example.demo.annotation.PreventRepeatSubmit;
import com.example.demo.mapper.StuMapper;
import com.example.demo.model.ResponseResult;
import com.example.demo.model.Student;
import com.example.demo.util.RedisBitMapUtils;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;@RestController
@RequestMapping("/test")
@Validated
public class TestController {@Resourceprivate StuMapper stuMapper;@Resourceprivate StringRedisTemplate stringRedisTemplate;private static final String BITMAP_STU="bitmap_stu";@Resourceprivate RedisBitMapUtils redisBitMapUtils;@GetMapping("init")public com.example.demo.util.ResponseResult init(){List<Student> studentList = stuMapper.selectList(new QueryWrapper<Student>());redisBitMapUtils.init(BITMAP_STU,studentList,Student::getId);return com.example.demo.util.ResponseResult.okResult();}/*** 編程式*/@GetMapping("selectStu1/{id}")@BitMap(key = BITMAP_STU,id = "#id")public com.example.demo.util.ResponseResult selectStu1(@PathVariable Integer id){return com.example.demo.util.ResponseResult.ok(stuMapper.selectById(id));}/*** 注解式*/@GetMapping("selectStu2/{id}")public com.example.demo.util.ResponseResult selectStu2(@PathVariable Integer id){if (redisBitMapUtils.getBit(BITMAP_STU,id)){return com.example.demo.util.ResponseResult.ok(stuMapper.selectById(id));}return com.example.demo.util.ResponseResult.okResult();}}

測試

初始化biemap數(shù)據(jù),從數(shù)據(jù)庫種獲取所有id并導(dǎo)入redis的key為bitmap_stu的數(shù)據(jù)

測試數(shù)據(jù)庫存在的數(shù)據(jù)id:1,走數(shù)據(jù)庫獲取數(shù)據(jù)?

測試數(shù)據(jù)庫的數(shù)據(jù)id:200,因為id為200不存在在數(shù)據(jù)庫中,所以沒有走數(shù)據(jù)庫,減少了數(shù)據(jù)庫壓力?

?注解式也生效

達到了使用redis的bitmap實現(xiàn)分布式的布隆過濾器,過濾掉bitmap不存在的數(shù)據(jù)?

http://www.risenshineclean.com/news/8543.html

相關(guān)文章:

  • wordpress破解百度seo優(yōu)化排名客服電話
  • 網(wǎng)站收錄量低怎么做常德網(wǎng)站設(shè)計
  • 中國企業(yè)500強江陰有幾家寧波seo外包公司
  • 做非法集資資訊的網(wǎng)站世界杯積分榜排名
  • 企業(yè)做網(wǎng)站維護價格專業(yè)seo優(yōu)化公司
  • 網(wǎng)站制作接單市場調(diào)研報告范文2000
  • 如何做獨立站個人網(wǎng)站推廣怎么做
  • 網(wǎng)站開發(fā)湛江西安搜索引擎優(yōu)化
  • 網(wǎng)站部分頻道完全不收錄了怎么做百度指數(shù)查詢移動版
  • 全球50個大網(wǎng)站開發(fā)語言昆明抖音推廣
  • 珠海市住房建設(shè)局網(wǎng)站十大外貿(mào)平臺
  • 如何自學(xué)網(wǎng)站制作網(wǎng)絡(luò)宣傳怎么做
  • 高端外貿(mào)網(wǎng)站建設(shè)服裝百度pc端首頁
  • 南京網(wǎng)站設(shè)計網(wǎng)站北京搜索引擎關(guān)鍵詞優(yōu)化
  • 網(wǎng)站設(shè)計需要什么專業(yè)關(guān)鍵詞優(yōu)化外包服務(wù)
  • 如何做盆栽蔬菜網(wǎng)站百度知道官網(wǎng)登錄入口
  • 專門做生鮮的網(wǎng)站打開百度搜索網(wǎng)站
  • 網(wǎng)上做任務(wù)賺錢的比較正規(guī)的網(wǎng)站seo顧問服務(wù) 樂云踐新專家
  • wordpress怎么看展現(xiàn)量北京百度推廣優(yōu)化排名
  • 什么網(wǎng)站做電器出租做網(wǎng)站建網(wǎng)站公司
  • 機關(guān)網(wǎng)站建設(shè)征求意見最新最好的磁力搜索
  • 大學(xué)生創(chuàng)業(yè)做網(wǎng)站網(wǎng)站流量統(tǒng)計分析
  • 公司網(wǎng)站的seo怎么做軟文推廣廣告
  • 汽車網(wǎng)站建設(shè)模板百度引流推廣哪家好
  • 紅谷灘園林建設(shè)集團有限公司 網(wǎng)站百度文庫首頁
  • 湖南網(wǎng)站托管哪家好廣州網(wǎng)站優(yōu)化步驟
  • 清遠專業(yè)網(wǎng)站制作公司360優(yōu)化大師官方下載最新版
  • 如何登錄網(wǎng)站空間sns營銷
  • 移動網(wǎng)站開發(fā)百度百科seo網(wǎng)絡(luò)優(yōu)化
  • 山東高端網(wǎng)站建設(shè)nba排名西部和東部