redisson -- 延迟队列RDelayedQueue

news/2025/3/14 22:11:56/

1.maven配置

<!-- 用于管理起步工程的依赖管理 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.11</version><relativePath/> </parent>
<dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.2</version></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>org.apache.commons</groupId><artifactId>commons-pool2</artifactId><version>2.6.2</version></dependency><dependency><groupId>org.redisson</groupId><artifactId>redisson-spring-boot-starter</artifactId><version>3.10.6</version></dependency>
</dependencies>

2.yml配置

server:port: 9007servlet:context-path: /spring:redis:# 超时时间timeout: 10000ms# 服务器地址host: 127.0.0.1# 服务器端口port: 6379# 数据库database: 0# 密码password: 123456lettuce:pool:# 最大连接数,默认8max-active: 1024# 最大连接阻塞等待时间,默认-1max-wait: 10000ms# 最大空闲连接max-idle: 200# 最小空闲连接min-idle: 5

3.config

java">import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;public class RedissonConfig {@Bean(destroyMethod = "shutdown")public RedissonClient redissonClient(RedisProperties redisProperties){Config config = new Config();SingleServerConfig singleServerConfig = config.useSingleServer();singleServerConfig.setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());singleServerConfig.setPassword(redisProperties.getPassword());singleServerConfig.setKeepAlive(true);// 根据config创建出RedissonClient实例RedissonClient redissonClient = Redisson.create(config);return redissonClient;}}

4.service

java">public void delayed() throws InterruptedException {// 阻塞队列:RBlockingDeque的实现类为:new RedissonBlockingDequeRBlockingDeque<String> blockingDeque = redissonClient.getBlockingDeque("delayedQueue");// 获取延迟队列RDelayedQueue<String> delayedQueue = redissonClient.getDelayedQueue(blockingDeque);System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "添加任务到延时队列里面");// 添加延迟任务delayedQueue.offer( "task1第一个任务", 6, TimeUnit.SECONDS);delayedQueue.offer( "task2第二个任务", 4, TimeUnit.SECONDS);System.out.println("--------------------Begin");// 通过 take 方法等待并获取到期的任务while (true) {String task = blockingDeque.take();System.out.println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "延时队列收到:" + task);}}

5.结果


http://www.ppmy.cn/news/1424478.html

相关文章

【Linux】基础I/O>文件系统软硬链接动静态库详解

主页&#xff1a;醋溜马桶圈-CSDN博客 专栏&#xff1a;Linux_醋溜马桶圈的博客-CSDN博客 gitee&#xff1a;mnxcc (mnxcc) - Gitee.com 目录 1.C语言文件接口 1.1 hello.c写文件 1.2 hello.c读文件 1.3 输出信息到显示器 1.4 stdin & stdout & stderr 1.5 总结打…

华为OD-C卷-路口最短时间问题[200分]Java 100%

题目描述 假定街道是棋盘型的,每格距离相等,车辆通过每格街道需要时间均为 timePerRoad; 街道的街口(交叉点)有交通灯,灯的周期 T(=lights[row][col])各不相同; 车辆可直行、左转和右转,其中直行和左转需要等相应 T 时间的交通灯才可通行,右转无需等待。 现给出…

如何使用OSI七层模型的思路进行Linux网络问题排障?

在运维工作中&#xff0c;我们可能经常遇到诸如服务器无法远程连接、网站无法访问等各种网络问题。此时你是否想过&#xff0c;我们常背的OSI七层模型&#xff0c;能在处理这样的实际问题中发挥什么样的作用呢&#xff1f; 基于OSI架构的方法论&#xff0c;我们可以使用自下而…

关于系统数据缓存的思考以及设计

文章目录 引言案例A项目B项目 分析我的实现总结 引言 缓存&#xff0c;这是一个经久不衰的话题&#xff0c;它通过“空间换时间”的战术不仅能够极大提升处理查询性能还能很好的保护底层资源。最近针对系统数据缓存的优化后&#xff0c;由于这是一个通用的场景并且有了一点心得…

再拓信创版图-Smartbi 与东方国信数据库完成兼容适配认证

近日&#xff0c;思迈特商业智能与数据分析软件 [简称&#xff1a;Smartbi Insight] V11与北京东方国信科技股份有限公司 &#xff08;以下简称东方国信&#xff09;CirroData-OLAP分布式数据库V2.14.1完成兼容性测试。经双方严格测试&#xff0c;两款产品能够达到通用兼容性要…

计算机网络(王道考研)笔记个人整理——第二章

第二章 物理层主要任务&#xff1a;确定与传输媒体有关的一些特性 机械特性&#xff1a;物理连接的特性 规定物理连接时所采用的规格、接口形状、引线数目、引脚数量和排列情况 电气特性 规定传输二进制位时&#xff0c;线路上信号的电压范围、阻抗匹配、传输速率和距离限制等…

VectorMap论文阅读

1. 摘要 自动驾驶系统需要对周围环境具有很好的理解&#xff0c;包括动态物体和静态高精度语义地图。现有方法通过离线手动标注来解决语义构图问题&#xff0c;这些方法存在严重的可扩展性问题。最近的基于学习的方法产生稠密的分割预测结果&#xff0c;这些预测不包含单个地图…

Oracle——领先的企业级数据库解决方案

一、WHAT IS ORACLWE&#xff1a; ORACLE 数据库系统是美国 ORACLE 公司&#xff08;甲骨文&#xff09;提供的以分布式数据库为核心的一组软件产品&#xff0c;是目前最流行的客户/服务器(CLIENT/SERVER)或B/S 体系结构的数据库之一&#xff0c;ORACLE 通常应用于大型系统的数…