package utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import java.text.DecimalFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* @Author Mr.ye
* @date 2022/5/30 09:53
* @Version 1.0
* @Description TODO
*/
public class RedisKeyUtil {
@Autowired
public RedisTemplate redisTemplate;
public static void main(String[] args) {
RedisKeyUtil redisKeyUtil = new RedisKeyUtil();
//生成唯一编码 CODE2022053095210001
redisKeyUtil.uniqueCode("CODE");
}
/**
* 生成编码
*
* @return str 标识符
*/
public String uniqueCode(String str) {
LocalDateTime dateTime = LocalDateTime.now();
String dateStr = dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
DecimalFormat df = new DecimalFormat("0000");
RedisAtomicLong counter = new RedisAtomicLong(str, redisTemplate.getConnectionFactory());
long count = counter.incrementAndGet();
StringBuilder sb = new StringBuilder(str).append(dateStr).append(df.format(count));
return sb.toString();
}
}
通过Redis生成唯一分布式key
于 2022-05-30 13:43:20 首次发布
博客涉及Java和Redis两种信息技术领域元素。Java是广泛使用的开发语言,Redis是高性能的键值对数据库。二者在后端开发等场景有重要应用。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Llama Factory
模型微调
LLama-Factory
LLaMA Factory 是一个简单易用且高效的大型语言模型(Large Language Model)训练与微调平台。通过 LLaMA Factory,可以在无需编写任何代码的前提下,在本地完成上百种预训练模型的微调
653

被折叠的 条评论
为什么被折叠?



