feat(cache): 在RedisUtils中增加increment方法并优化验证码缓存服务

- 新增RedisUtils.increment方法用于原子递增操作
- 重构CaptchaCacheServiceProvider使用RedisUtils替代直接stringRedisTemplate调用
- 统一Redis缓存操作工具类方法调用方式
This commit is contained in:
PIG AI committed 2025-07-04 12:24:28 +08:00
1 parent bf1e58fb71
commit 00efa97eef
2 files changed
+15 -1

No files matched your search

@@ -40,7 +40,7 @@ public class CaptchaCacheServiceProvider implements CaptchaCacheService {
@Override
public Long increment(String key, long val) {
return stringRedisTemplate.opsForValue().increment(key, val);
return RedisUtils.increment(key, val);
}
}
@@ -270,6 +270,20 @@ public class RedisUtils {
return (T) redisTemplate.execute(callback);
}
/**
* 递增操作
*
* @param key 键
* @param val 增加的值
* @return 递增后的值
*/
public Long increment(String key, long val) {
RedisTemplate<String, Object> redisTemplate = SpringContextHolder.getBean(RedisTemplate.class);
return Optional.ofNullable(redisTemplate)
.map(template -> template.opsForValue().increment(key, val))
.orElse(null);
}
// ================================Map=================================
/**