|
@@ -17,7 +17,7 @@ import com.fs.live.vo.LiveGoodsVo;
|
|
|
import com.fs.live.vo.LiveOrderTipVo;
|
|
import com.fs.live.vo.LiveOrderTipVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -63,6 +63,9 @@ public class LiveOrderTipServiceImpl implements ILiveOrderTipService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsUserScrmService fsUserService;
|
|
private IFsUserScrmService fsUserService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
+
|
|
|
/** 内置默认昵称库(前端/后台未配置时兜底使用) */
|
|
/** 内置默认昵称库(前端/后台未配置时兜底使用) */
|
|
|
private static final List<String> DEFAULT_NICKNAMES = Collections.unmodifiableList(Arrays.asList(
|
|
private static final List<String> DEFAULT_NICKNAMES = Collections.unmodifiableList(Arrays.asList(
|
|
|
"养生小达人", "健康路上", "乐活青年", "品味生活", "星月同辉",
|
|
"养生小达人", "健康路上", "乐活青年", "品味生活", "星月同辉",
|
|
@@ -236,10 +239,10 @@ public class LiveOrderTipServiceImpl implements ILiveOrderTipService {
|
|
|
String member = now + "-" + UUID.randomUUID();
|
|
String member = now + "-" + UUID.randomUUID();
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
|
|
- RedisTemplate<String, Object> template = (RedisTemplate<String, Object>) redisCache.redisTemplate;
|
|
|
|
|
DefaultRedisScript<Long> script = new DefaultRedisScript<>(RATE_LIMIT_LUA, Long.class);
|
|
DefaultRedisScript<Long> script = new DefaultRedisScript<>(RATE_LIMIT_LUA, Long.class);
|
|
|
- Long result = template.execute(
|
|
|
|
|
|
|
+ // 使用 StringRedisTemplate,避免 GenericJackson2JsonRedisSerializer 把 ARGV 序列化成带引号字符串,
|
|
|
|
|
+ // 导致 Redis 报错:ERR min or max is not a float
|
|
|
|
|
+ Long result = stringRedisTemplate.execute(
|
|
|
script,
|
|
script,
|
|
|
Collections.singletonList(key),
|
|
Collections.singletonList(key),
|
|
|
String.valueOf(now),
|
|
String.valueOf(now),
|
|
@@ -264,8 +267,8 @@ public class LiveOrderTipServiceImpl implements ILiveOrderTipService {
|
|
|
long now = System.currentTimeMillis();
|
|
long now = System.currentTimeMillis();
|
|
|
long start = now - windowSec * 1000L;
|
|
long start = now - windowSec * 1000L;
|
|
|
try {
|
|
try {
|
|
|
- redisCache.redisTemplate.opsForZSet().removeRangeByScore(key, 0, start);
|
|
|
|
|
- Long cnt = redisCache.redisTemplate.opsForZSet().zCard(key);
|
|
|
|
|
|
|
+ stringRedisTemplate.opsForZSet().removeRangeByScore(key, 0, start);
|
|
|
|
|
+ Long cnt = stringRedisTemplate.opsForZSet().zCard(key);
|
|
|
int used = cnt == null ? 0 : cnt.intValue();
|
|
int used = cnt == null ? 0 : cnt.intValue();
|
|
|
return Math.max(0, max - used);
|
|
return Math.max(0, max - used);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|