package cn.zwz.basics.redis;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Component;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* @author 郑为中
* CSDN: Designer 小郑
*/
@ApiOperation(value = "Redis工具类")
@Component
public class RedisTemplateHelper {
@Autowired
private StringRedisTemplate redisTemplate;
@ApiOperation(value = "scan实现")
private void scan(String wayForScan, Consumer<byte[]> consumableList) {
redisTemplate.execute((RedisConnection connection) -> {
try (Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().count(Long.MAX_VALUE).match(wayForScan).build())) {
cursor.forEachRemaining(consumableList);
return null;
} catch (Exception exception) {
throw new RuntimeException(exception);
}
});
}
@ApiOperation(value = "scan获取符合条件的key")
public Set<String> scan(String pattern) {
Set<String> keys = new HashSet<>();
this.scan(pattern, item -> {
String key = new String(item, StandardCharsets.UTF_8);
keys.add(key);
});
return keys;
}
@ApiOperation(value = "通过通配符表达式删除所有")
public void deleteByPattern(String pattern) {
Set<String> keys = this.scan(pattern);
redisTemplate.delete(keys);
}
@ApiOperation(value = "删除key")
public void delete(String key) {
redisTemplate.delete(key);
}
@ApiOperation(value = "批量删除key")
public void delete(Collection<String> keys) {
redisTemplate.delete(keys);
}
@ApiOperation(value = "序列化key")
public byte[] dump(String key) {
return redisTemplate.dump(key);
}
@ApiOperation(value = "是否存在key")
public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
@ApiOperation(value = "设置过期时间")
public Boolean expire(String key, long timeout, TimeUnit unit) {
return redisTemplate.expire(key, timeout, unit);
}
@ApiOperation(value = "设置过期时间")
public Boolean expireAt(String key, Date date) {
return redisTemplate.expireAt(key, date);
}
@ApiOperation(value = "查找匹配的key")
public Set<String> keys(String pattern) {
return redisTemplate.keys(pattern);
}
@ApiOperation(value = "将当前数据库的 key 移动到给定的数据库 db 当中")
public Boolean move(String key, int dbIndex) {
return redisTemplate.move(key, dbIndex);
}
@ApiOperation(value = "移除 key 的过期时间,key 将持久保持")
public Boolean persist(String key) {
return redisTemplate.persist(key);
}
@ApiOperation(value = "返回 key 的剩余的过期时间")
public Long getExpire(String key, TimeUnit unit) {
return redisTemplate.getExpire(key, unit);
}
@ApiOperation(value = "返回 key 的剩余的过期时间")
public Long getExpire(String key) {
return redisTemplate.getExpire(key);
}
@ApiOperation(value = "从当前数据库中随机返回一个 key")
public String randomKey() {
return redisTemplate.randomKey();
}
@ApiOperation(value = "修改 key 的名称")
public void rename(String oldKey, String newKey) {
redisTemplate.rename(oldKey, newKey);
}
@ApiOperation(value = "仅当 newkey 不存在时,将 oldKey 改名为 newkey")
public Boolean renameIfAbsent(String oldKey, String newKey) {
return redisTemplate.renameIfAbsent(oldKey, newKey);
}
@ApiOperation(value = "返回 key 所储存的值的类型")
public DataType type(String key) {
return redisTemplate.type(key);
}
/** -------------------string相关操作--------------------- */
@ApiOperation(value = "设置指定 key 的值")
public void set(String key, String value) {
redisTemplate.opsForValue().set(key, value);
}
@ApiOperation(value = "将值 value 关联到 key ,并将 key 的过期时间设为 timeout")
public void set(String key, String value, long timeout, TimeUnit unit) {
redisTemplate.opsForValue().set(key, value, timeout, unit);
}
@ApiOperation(value = "获取指定 key 的值")
public String get(String key) {
return redisTemplate.opsForValue().get(key);
}
@ApiOperation(value = "返回 key 中字符串值的子字符")
public String getRange(String key, long start, long end) {
return redisTemplate.opsForValue().get(key, start, end);
}
@ApiOperation(value = "将给定 key 的值设为 value ,并返回 key 的旧值(old value)")
public String getAndSet(String key, String value) {
return redisTemplate.opsForValue().getAndSet(key, value);
}
@ApiOperation(value = "对 key 所储存的字符串值,获取指定偏移量上的位(bit)")
public Boolean getBit(String key, long offset) {
return redisTemplate.opsForValue().getBit(key, offset);
}
@ApiOperation(value = "批量获取")
public List<String> multiGet(Collection<String> keys) {
return redisTemplate.opsForValue().multiGet(keys);
}
@ApiOperation(value = "设置ASCII码, 字符串'a'的ASCII码是97, 转为二进制是'01100001', 此方法是将二进制第offset位值变为value",notes = "offset 位置, value: 值,true为1, false为0")
public boolean setBit(String key, long offset, boolean value) {
return redisTemplate.opsForValue().setBit(key, offset, value);
}
@ApiOperation(value = "只有在 key 不存在时设置 key 的值",notes = "之前已经存在返回false, 不存在返回true")
public boolean setIfAbsent(String key, String value) {
return redisTemplate.opsForValue().setIfAbsent(key, value);
}
@ApiOperation(value = "用 value 参数覆写给定 key 所储存的字符串值,从偏移量 offset 开始",notes = "offset:从指定位置开始覆写")
public void setRange(String key, String value, long offset) {
redisTemplate.opsForValue().set(key, value, offset);
}
@ApiOperation(value = "获取字符串的长度")
public Long size(String key) {
return redisTemplate.opsForValue().size(key);
}
@ApiOperation(value = "批量添加")
public void multiSet(Map<String, String> maps) {
redisTemplate.opsForValue().multiSet(maps);
}
@ApiOperation(value = "同时设置一个或多个 key-value 对,当且仅当所有给定 key 都不存在")
public boolean multiSetIfAbsent(Map<String, String> maps) {
return redisTemplate.opsForValue().multiSetIfAbsent(maps);
}
@ApiOperation(value = "增加(自增长), 负数则为自减")
public Long incrBy(String key, long increment) {
return redisTemplate.opsForValue().increment(key, increment);
}
@ApiOperation(value = "增加(自增长)")
public Double incrByFloat(String key, double increment) {
return redisTemplate.opsForValue().increment(key, increment);
}
@ApiOperation(value = "追加到末尾")
public Integer append(String key, String value) {
return redisTemplate.opsForValue().append(key, value);
}
// hash表
@ApiOperation(value = "获取存储在哈希表中指定字段的值")
public Object hGet
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
**Spring Boot和Vue结合的高校宿舍调配管理系统是基于Java、Vue.js、Spring Boot和MySQL技术的高效宿舍管理解决方案**。 该系统为高校管理员、教师和学生提供了角色定制的功能,可以实现精确到按钮级别的权限控制,适用于对权限管理要求较高的场景[^1^][^5^]。该系统主要包括以下几个部分: 1. **宿舍管理模块**:负责管理宿舍的基本信息,包括宿舍楼、楼层和房间号等[^1^][^3^]。 2. **宿舍分配模块**:通过算法(如K-means或贪心算法)自动分配宿舍,并处理调宿申请[^1^][^5^]。 3. **个人配置模块**:允许用户填写和管理个人信息,以及查看宿舍分配结果和舍友信息[^1^][^5^]。 4. **基础功能模块**:包含用户管理、部门管理、角色管理、菜单管理、日志管理、数据字典管理、文件管理和图表展示等,确保系统的全面性和易用性[^1^][^5^]。 该系统适用于需要精细化管理的高校宿舍环境,可以帮助提升宿舍管理的效率和准确性,减少人工操作的繁琐性和出错率[^2^][^4^]。具体介绍如下: 1. **系统特点**
资源推荐
资源详情
资源评论




























收起资源包目录





































































































共 300 条
- 1
- 2
- 3
资源评论


程序员柚子
- 粉丝: 842
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 吴恩达机器学习公开课程作业中文版本及 Python 实现内容
- 论文针对航空发动机控制问题,提出了一种基于切换系统方法的固定时间控制器设计(含详细代码及解释)
- 电力系统电动汽车参与电量与备用市场联合风险调度:基于合约机制与多场景优化的收益最大化模型设计(含详细代码及解释)
- 这篇文章详细探讨了小电流接地系统中单相接地故障选线的新原理和技术实现,旨在解决传统选线方法在面对参数变化和高阻故障时准确率低的问题(含详细代码及解释)
- 基于C语言的码元同步程序
- 解决裂缝型储层压裂后复杂人工裂缝网络难以定量诊断的问题(含详细代码及解释)
- 机器学习基于SVM的糖尿病数据分类模型构建与分析:从数据预处理到模型评估的全流程实践(含详细代码及解释)
- ROS、工业自动化、OpenCV、3D 点云与机器学习在机械臂中的应用
- 【金属增材制造】高强铝合金电弧增材制造工艺研究及优化:从理论建模到工业应用的全面解析(含详细代码及解释)
- 【电力系统调频】基于VMD的储能辅助火电机组二次调频控制策略及容量优化配置研究(含详细代码及解释)
- 2025电赛备赛-Maixcam视觉模块
- 【自然语言处理】基于扩散模型的DiffusionSL序列标注方法:非自回归标签生成与优化usionSL(含详细代码及解释)
- Coursera 平台林轩田教授主讲的机器学习课程
- 【无刷直流电动机】基于PWM调制策略的换相转矩脉动抑制技术实现与分析:三相协同调制算法在全速域的应用(含详细代码及解释)
- 【航空市场竞争结构分析】基于进入与定价决策的计量经济学模型:Python代码实现与反事实分析(含详细代码及解释)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
