Ver código fonte

直播下单运营1

xw 6 dias atrás
pai
commit
0e52632684

+ 9 - 6
fs-service/src/main/java/com/fs/live/service/impl/LiveOrderTipServiceImpl.java

@@ -17,7 +17,7 @@ import com.fs.live.vo.LiveGoodsVo;
 import com.fs.live.vo.LiveOrderTipVo;
 import lombok.extern.slf4j.Slf4j;
 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.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -63,6 +63,9 @@ public class LiveOrderTipServiceImpl implements ILiveOrderTipService {
     @Autowired
     private IFsUserScrmService fsUserService;
 
+    @Autowired
+    private StringRedisTemplate stringRedisTemplate;
+
     /** 内置默认昵称库(前端/后台未配置时兜底使用) */
     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();
 
         try {
-            @SuppressWarnings("unchecked")
-            RedisTemplate<String, Object> template = (RedisTemplate<String, Object>) redisCache.redisTemplate;
             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,
                     Collections.singletonList(key),
                     String.valueOf(now),
@@ -264,8 +267,8 @@ public class LiveOrderTipServiceImpl implements ILiveOrderTipService {
         long now = System.currentTimeMillis();
         long start = now - windowSec * 1000L;
         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();
             return Math.max(0, max - used);
         } catch (Exception e) {