package com.chinaztt.mes.basic.util; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; /** * @Author: Zero * @Date: 2022/10/21 10:39 * @Description: */ @Component public class RedisUtils { @Autowired private RedisTemplate redisTemplate; /** * 递增 *
最终redis中的key为 businessName:prefix
* * @param businessName 业务名 * @param prefix 前缀 * @param delta 要增加几(大于0) * @return */ public long incr(String businessName, String prefix, long delta) { if (delta < 0) { throw new RuntimeException("步长必须大于0"); } return redisTemplate.opsForValue().increment(businessName + ":" + prefix, delta); } }