fix:创建订单增加节流操作

This commit is contained in:
张松
2024-12-06 13:57:51 +08:00
parent 4229c500ad
commit c51d8325c2

View File

@@ -136,6 +136,8 @@ public class Utils {
if (prevTimestamp == null || prevCount == null) { if (prevTimestamp == null || prevCount == null) {
redisTemplate.opsForValue().set(key + ":timestamp", String.valueOf(now)); redisTemplate.opsForValue().set(key + ":timestamp", String.valueOf(now));
redisTemplate.opsForValue().set(key + ":count", "1"); redisTemplate.opsForValue().set(key + ":count", "1");
redisTemplate.expire(key + ":timestamp", 5, TimeUnit.SECONDS);
redisTemplate.expire(key + ":count", 5, TimeUnit.SECONDS);
return; return;
} }
@@ -146,6 +148,8 @@ public class Utils {
if (elapsed > timeWindow) { if (elapsed > timeWindow) {
redisTemplate.opsForValue().set(key + ":timestamp", String.valueOf(now)); redisTemplate.opsForValue().set(key + ":timestamp", String.valueOf(now));
redisTemplate.opsForValue().set(key + ":count", "1"); redisTemplate.opsForValue().set(key + ":count", "1");
redisTemplate.expire(key + ":timestamp", 5, TimeUnit.SECONDS);
redisTemplate.expire(key + ":count", 5, TimeUnit.SECONDS);
return; return;
} }
@@ -160,5 +164,7 @@ public class Utils {
// 更新计数和时间戳 // 更新计数和时间戳
redisTemplate.opsForValue().set(key + ":count", String.valueOf(count)); redisTemplate.opsForValue().set(key + ":count", String.valueOf(count));
redisTemplate.opsForValue().set(key + ":timestamp", String.valueOf(now)); redisTemplate.opsForValue().set(key + ":timestamp", String.valueOf(now));
redisTemplate.expire(key + ":timestamp", 5, TimeUnit.SECONDS);
redisTemplate.expire(key + ":count", 5, TimeUnit.SECONDS);
} }
} }