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

RedisCache存入redis的数据key为何name和id的分隔符是两个冒号::

Redis Cache缓存数据生成的key是由两部分组成,cacheNames和+d或者自定义生成方案,如果采用cacheNames+id方案则会在中间添加两个冒号::,这样使用工具查看的时候感觉怪怪的,今天我们就探讨下具体生成原因。

一、CacheKeyPrefix钩子回调接口
@FunctionalInterface
public interface CacheKeyPrefix {String SEPARATOR = "::";String compute(String cacheName);static CacheKeyPrefix simple() {return name -> name + SEPARATOR;}static CacheKeyPrefix prefixed(String prefix) {Assert.notNull(prefix, "Prefix must not be null");return name -> prefix + name + SEPARATOR;}
}

回调函数定义了simple()和prefixed()两个方法将定义的name和双冒号拼接

二、具体使用代码RedisCacheConfiguration#prefixCacheNameWith
	/*** Prefix the {@link RedisCache#getName() cache name} with the given value. <br />* The generated cache key will be: {@code prefix + cache name + "::" + cache entry key}.** @param prefix the prefix to prepend to the cache name.* @return new {@link RedisCacheConfiguration}.* @see #computePrefixWith(CacheKeyPrefix)* @see CacheKeyPrefix#prefixed(String)* @since 2.3*/public RedisCacheConfiguration prefixCacheNameWith(String prefix) {return computePrefixWith(CacheKeyPrefix.prefixed(prefix));}

注解标记拼接方案是:prefix + cache name + “::” + cache entry key

三、配置类RedisCacheConfiguration#createConfiguration调用上述方法
	private org.springframework.data.redis.cache.RedisCacheConfiguration createConfiguration(CacheProperties cacheProperties, ClassLoader classLoader) {Redis redisProperties = cacheProperties.getRedis();org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration.defaultCacheConfig();config = config.serializeValuesWith(SerializationPair.fromSerializer(new JdkSerializationRedisSerializer(classLoader)));if (redisProperties.getTimeToLive() != null) {config = config.entryTtl(redisProperties.getTimeToLive());}if (redisProperties.getKeyPrefix() != null) {// 配置cacheName组合方案config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());}if (!redisProperties.isCacheNullValues()) {config = config.disableCachingNullValues();}if (!redisProperties.isUseKeyPrefix()) {config = config.disableKeyPrefix();}return config;}

开源SDK:https://github.com/mingyang66/spring-parent

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 2024年高教社杯全国大学生数学建模竞赛A题思路(2024数学建模国赛A题思路)
  • 【Effective Java】多构造器参数使用构建器 (快速上手)
  • 【HuggingFace Transformers】OpenAIGPTModel源码解析
  • MySQL学习--加强
  • MATLAB算法实战应用案例精讲-【人工智能】数据集市(概念篇)
  • 电子发射与气体导电
  • 【免费分享】25秋招提前批25秋招信息表
  • 《Cloud Native Data Center Networking》(云原生数据中心网络设计)读书笔记 -- 09部署OSPF
  • Gitflow基础知识
  • 【Python知识宝库】文件操作:读写文件的最佳实践
  • fetch-event-source 如何通过script全局引入
  • Autosar(Davinci) --- 创建一个S/R类型的port(下)
  • 【数据分享】《中国城市统计年鉴》(1985-2023)全PDF版本 第一次补档
  • linux curl命令介绍以及使用
  • 探索Pyro4:Python中的远程对象通信艺术
  • 9月CHINA-PUB-OPENDAY技术沙龙——IPHONE
  • __proto__ 和 prototype的关系
  • 【许晓笛】 EOS 智能合约案例解析(3)
  • 【跃迁之路】【444天】程序员高效学习方法论探索系列(实验阶段201-2018.04.25)...
  • 30秒的PHP代码片段(1)数组 - Array
  • Android Volley源码解析
  • CSS 三角实现
  • express + mock 让前后台并行开发
  • Java的Interrupt与线程中断
  • JDK9: 集成 Jshell 和 Maven 项目.
  • js继承的实现方法
  • laravel 用artisan创建自己的模板
  • NLPIR语义挖掘平台推动行业大数据应用服务
  • 第2章 网络文档
  • 基于游标的分页接口实现
  • nb
  • Hibernate主键生成策略及选择
  • 曜石科技宣布获得千万级天使轮投资,全方面布局电竞产业链 ...
  • 智能情侣枕Pillow Talk,倾听彼此的心跳
  • ​DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • ​ssh-keyscan命令--Linux命令应用大词典729个命令解读
  • # 20155222 2016-2017-2 《Java程序设计》第5周学习总结
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • (1)(1.11) SiK Radio v2(一)
  • (1)STL算法之遍历容器
  • (c语言版)滑动窗口 给定一个字符串,只包含字母和数字,按要求找出字符串中的最长(连续)子串的长度
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (JS基础)String 类型
  • (Mirage系列之二)VMware Horizon Mirage的经典用户用例及真实案例分析
  • (七)c52学习之旅-中断
  • (区间dp) (经典例题) 石子合并
  • (转载)(官方)UE4--图像编程----着色器开发
  • ***通过什么方式***网吧
  • *Django中的Ajax 纯js的书写样式1
  • .helper勒索病毒的最新威胁:如何恢复您的数据?
  • .NET CF命令行调试器MDbg入门(四) Attaching to Processes
  • .NET Remoting学习笔记(三)信道
  • .net 程序发生了一个不可捕获的异常
  • @EnableAsync和@Async开始异步任务支持