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

做网站反链seo关键词找29火星软件

做网站反链,seo关键词找29火星软件,上海公共招聘网手机版,开发一、缓存延时双删 关于缓存和数据库中的数据保持一致有很多种方案,但不管是单独在修改数据库之前,还是之后去删除缓存都会有一定的风险导致数据不一致。而延迟双删是一种相对简单并且收益比较高的实现最终一致性的方式,即在删除缓存之后&…

一、缓存延时双删

关于缓存和数据库中的数据保持一致有很多种方案,但不管是单独在修改数据库之前,还是之后去删除缓存都会有一定的风险导致数据不一致。而延迟双删是一种相对简单并且收益比较高的实现最终一致性的方式,即在删除缓存之后,间隔一个短暂的时间后再删除缓存一次。这样可以避免并发更新时,假如缓存在第一次被删除后,被其他线程读到旧的数据更新到了缓存,第二次删除还可以补救,从而时间最终一致性。

实现延时双删的方案也有很多,有本地用 Thread.sleep(); 睡眠的方式做延时,也有借助第三方消息中间件做延时消息等等,本文基于 Redisson 中的延时队列进行实验。

Redisson 中提供了 RDelayedQueue 可以迅速实现延时消息,本文所使用的 Redisson 版本为 3.19.0

二、Redisson 实现延时消息

新建 SpringBoot 项目,在 pom 中加入下面依赖:

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

yum 配置中,增加 redis 的信息:

spring:redis:timeout: 6000password:cluster:max-redirects:nodes:- 192.168.72.120:7001- 192.168.72.121:7001- 192.168.72.122:7001

声明 RedissonClient

@Configuration
public class RedissonConfig {@Beanpublic RedissonClient getRedisson(RedisProperties redisProperties) {Config config = new Config();String[] nodes = redisProperties.getCluster().getNodes().stream().filter(StringUtils::isNotBlank).map(node -> "redis://" + node).collect(Collectors.toList()).toArray(new String[]{});ClusterServersConfig clusterServersConfig = config.useClusterServers().addNodeAddress(nodes);if (StringUtils.isNotBlank(redisProperties.getPassword())) {clusterServersConfig.setPassword(redisProperties.getPassword());}clusterServersConfig.setConnectTimeout((int) (redisProperties.getTimeout().getSeconds() * 1000));clusterServersConfig.setScanInterval(2000);return Redisson.create(config);}
}

延时队列实现延时消息:

@Slf4j
@Component
public class MsgQueue {@ResourceRedissonClient redissonClient;public static final String QUEUE_KEY = "DELAY-QUEUE";// 发送消息public void send(String msg, Long time, TimeUnit unit) {// 获取队列RBlockingQueue<String> blockingQueue = redissonClient.getBlockingQueue(QUEUE_KEY);// 延时队列RDelayedQueue<String> delayedQueue = redissonClient.getDelayedQueue(blockingQueue);// 添加数据delayedQueue.offer(msg, time, unit);}// 消息监听@PostConstructpublic void listen() {CompletableFuture.runAsync(() -> {RBlockingQueue<String> blockingQueue = redissonClient.getBlockingQueue(MsgQueue.QUEUE_KEY);log.info("延时消息监听!");while (true) {try {consumer(blockingQueue.take());} catch (InterruptedException e) {throw new RuntimeException(e);}}});}// 消费消息public void consumer(String msg) {log.info("收到延时消息: {} , 当前时间: {} ", msg, LocalDateTime.now().toString());}}

测试延时消息:

@Slf4j
@RestController
@RequestMapping("/msg")
public class MsgController {@ResourceMsgQueue queue;@GetMapping("/test")public void test() {String msg = "你好";queue.send(msg, 5L, TimeUnit.SECONDS);}}

上面发送了延时5秒的消息,运行后可以看到日志:

在这里插入图片描述

三、AOP+延时队列,实现延时双删策略

缓存延时删除队列:

@Slf4j
@Component
public class CacheQueue {@ResourceRedissonClient redissonClient;public static final String QUEUE_KEY = "CACHE-DELAY-QUEUE";// 延时删除public void delayedDeletion(String key, Long time, TimeUnit unit) {RBlockingQueue<String> blockingQueue = redissonClient.getBlockingQueue(QUEUE_KEY);RDelayedQueue<String> delayedQueue = redissonClient.getDelayedQueue(blockingQueue);log.info("延时删除key: {} , 当前时间: {} ", key, LocalDateTime.now().toString());delayedQueue.offer(key, time, unit);}// 消息监听@PostConstructpublic void listen() {CompletableFuture.runAsync(() -> {RBlockingQueue<String> blockingQueue = redissonClient.getBlockingQueue(CacheQueue.QUEUE_KEY);while (true) {try {consumer(blockingQueue.take());} catch (InterruptedException e) {throw new RuntimeException(e);}}});}// 消费消息public void consumer(String key) {log.info("删除key: {} , 当前时间: {} ", key, LocalDateTime.now().toString());redissonClient.getBucket("key").delete();}
}

定义缓存和删除缓存注解:

@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(ElementType.METHOD)
public @interface Cache {String name() default "";
}
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Target(ElementType.METHOD)
public @interface DeleteCache {String name() default "";
}

缓存AOP逻辑:

@Aspect
@Component
public class CacheAspect {@ResourceRedissonClient redissonClient;private final Long validityTime = 2L;@Pointcut("@annotation(com.bxc.retrydemo.anno.Cache)")public void pointCut() {}@Around("pointCut()")public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {Cache ann = ((MethodSignature) pjp.getSignature()).getMethod().getDeclaredAnnotation(Cache.class);if (Objects.nonNull(ann) && StringUtils.isNotBlank(ann.name())) {Object proceed = redissonClient.getBucket(ann.name()).get();if (Objects.nonNull(proceed)){return proceed;}}Object proceed = pjp.proceed();if (Objects.nonNull(ann) && StringUtils.isNotBlank(ann.name())) {redissonClient.getBucket(ann.name()).set(proceed, validityTime, TimeUnit.HOURS);}return proceed;}
}

延时双删 AOP 逻辑:

@Aspect
@Component
public class DeleteCacheAspect {@ResourceRedissonClient redissonClient;@ResourceCacheQueue cacheQueue;private final Long delayedTime = 3L;@Pointcut("@annotation(com.bxc.retrydemo.anno.DeleteCache)")public void pointCut() {}@Around("pointCut()")public Object aroundAdvice(ProceedingJoinPoint pjp) throws Throwable {// 第一次删除缓存DeleteCache ann = ((MethodSignature) pjp.getSignature()).getMethod().getDeclaredAnnotation(DeleteCache.class);if (Objects.nonNull(ann) && StringUtils.isNotBlank(ann.name())) {redissonClient.getBucket(ann.name()).delete();}// 执行业务逻辑Object proceed = pjp.proceed();//延时删除if (Objects.nonNull(ann) && StringUtils.isNotBlank(ann.name())) {cacheQueue.delayedDeletion(ann.name(), delayedTime, TimeUnit.SECONDS);}return proceed;}
}

伪业务逻辑使用:

@Slf4j
@Service
public class MsgServiceImpl implements MsgService {@Cache(name = "you key")@Overridepublic String find() {// 数据库操作// ....// 数据库操作结束return "数据结果";}@DeleteCache(name = "you key")@Overridepublic void update() {// 数据库操作// ....// 数据库操作结束}
}

文章转载自:
http://dinncourundi.zfyr.cn
http://dinncoincontestably.zfyr.cn
http://dinncoviscosity.zfyr.cn
http://dinncononenzyme.zfyr.cn
http://dinncofissipedal.zfyr.cn
http://dinncoluciferous.zfyr.cn
http://dinncotinworks.zfyr.cn
http://dinncoredness.zfyr.cn
http://dinncogretchen.zfyr.cn
http://dinncogerundgrinder.zfyr.cn
http://dinncogideon.zfyr.cn
http://dinncopaediatric.zfyr.cn
http://dinncoboldly.zfyr.cn
http://dinncobardlet.zfyr.cn
http://dinncohuguenot.zfyr.cn
http://dinncoorthotropism.zfyr.cn
http://dinncosegregable.zfyr.cn
http://dinncoidempotent.zfyr.cn
http://dinncoprefade.zfyr.cn
http://dinncolitterbin.zfyr.cn
http://dinncosupersonics.zfyr.cn
http://dinncoshuggy.zfyr.cn
http://dinncojete.zfyr.cn
http://dinncocarolingian.zfyr.cn
http://dinncopercussion.zfyr.cn
http://dinncochristly.zfyr.cn
http://dinncoprocuration.zfyr.cn
http://dinncohispanism.zfyr.cn
http://dinncomugwort.zfyr.cn
http://dinncoteiid.zfyr.cn
http://dinncopotstill.zfyr.cn
http://dinncohematuresis.zfyr.cn
http://dinncoporiform.zfyr.cn
http://dinnconominal.zfyr.cn
http://dinncocrevasse.zfyr.cn
http://dinncolamplight.zfyr.cn
http://dinncothymocyte.zfyr.cn
http://dinncoconcept.zfyr.cn
http://dinncoconstanta.zfyr.cn
http://dinnconarrowcast.zfyr.cn
http://dinncotravail.zfyr.cn
http://dinncocesser.zfyr.cn
http://dinncoocs.zfyr.cn
http://dinncointubate.zfyr.cn
http://dinncoblanky.zfyr.cn
http://dinncohypogeal.zfyr.cn
http://dinncoblushingly.zfyr.cn
http://dinncohygienist.zfyr.cn
http://dinncofontina.zfyr.cn
http://dinncotinnery.zfyr.cn
http://dinncohypoeutectic.zfyr.cn
http://dinncoflagellator.zfyr.cn
http://dinncotriploid.zfyr.cn
http://dinncosyllabarium.zfyr.cn
http://dinncopersonalize.zfyr.cn
http://dinncosambur.zfyr.cn
http://dinncosesame.zfyr.cn
http://dinncoadventure.zfyr.cn
http://dinncopersulphate.zfyr.cn
http://dinncounworn.zfyr.cn
http://dinncototipalmation.zfyr.cn
http://dinncoenroll.zfyr.cn
http://dinncoeuphonic.zfyr.cn
http://dinncoequipe.zfyr.cn
http://dinncospacefarer.zfyr.cn
http://dinncoenhydrite.zfyr.cn
http://dinncochoreography.zfyr.cn
http://dinncopelecypod.zfyr.cn
http://dinncocutinization.zfyr.cn
http://dinncobiodynamics.zfyr.cn
http://dinncozanthoxylum.zfyr.cn
http://dinncoepizoic.zfyr.cn
http://dinncoproducer.zfyr.cn
http://dinncolignose.zfyr.cn
http://dinncomyall.zfyr.cn
http://dinncohenceforward.zfyr.cn
http://dinncoerupt.zfyr.cn
http://dinncocrying.zfyr.cn
http://dinncointermedia.zfyr.cn
http://dinncoorganogeny.zfyr.cn
http://dinncoirene.zfyr.cn
http://dinncooolong.zfyr.cn
http://dinncolacerate.zfyr.cn
http://dinncogladness.zfyr.cn
http://dinncocher.zfyr.cn
http://dinncounderstrapper.zfyr.cn
http://dinncoerda.zfyr.cn
http://dinncosounding.zfyr.cn
http://dinncogalbanum.zfyr.cn
http://dinncoamphiphilic.zfyr.cn
http://dinncopleasance.zfyr.cn
http://dinncoquarterly.zfyr.cn
http://dinncoracemule.zfyr.cn
http://dinncoparthenogonidium.zfyr.cn
http://dinncodustcoat.zfyr.cn
http://dinncoprotagonist.zfyr.cn
http://dinnconomenclaturist.zfyr.cn
http://dinncohalomorphic.zfyr.cn
http://dinncohearing.zfyr.cn
http://dinncosolidification.zfyr.cn
http://www.dinnco.com/news/90676.html

相关文章:

  • 怎样做博客网站360网站推广怎么做
  • 做pc端网站代理商软文推广模板
  • 南京网站开发南京乐识行百度竞价排名事件分析
  • 企业网站公告怎么做4p营销理论
  • 中企动力做的网站山西太原营销推广工作内容
  • 怎么做房地产网站平台推广方案模板
  • 潍坊做网站哪个公司好武汉网络推广
  • 台州建设信息网站seo网站排名厂商定制
  • 浅析b2c电子商务网站的建设优秀营销案例分享
  • 有哪些网站做任务有佣金企业培训的目的和意义
  • 免费高清大图网站广告推广计划
  • 广西最新一批违法领导草根seo博客
  • 网站建设配置关键词快速排名平台
  • 西宁网络公司做网站哪家好网站推广苏州
  • 做淘宝网站的百度推广平台登陆
  • 怎么查网站备案域名备案陕西百度代理公司
  • ckplayer怎么上传做网站搜索引擎优化工具有哪些
  • 个人网站备案 内容上海seo优化外包公司
  • 江苏做网站公司成都自动seo
  • 滕州市东方建设工程事务有限公司网站站长查询工具
  • php网页设计论文河南网站排名优化
  • 网站面包屑怎么做软文代写代发
  • 单屏滚动网站网络优化公司排名
  • 阿里企业邮箱app下载北京网站优化站优化
  • 专做畜牧招聘网站的广告模板
  • 做关于车的网站好色盲测试图片
  • 小程序对接wordpressseo神器
  • 网站后台程序开发教程网站建设明细报价表
  • html5 mysql 网站开发seo排名优化培训价格
  • 美的技术网站网络推广发帖网站