优化代码

This commit is contained in:
ChenYi 2025-04-17 09:10:01 +08:00
parent cadb69f4b9
commit 4737c5b53d

View File

@ -7,6 +7,7 @@ using JiShe.CollectBus.Common.Models;
using JiShe.CollectBus.FreeRedisProvider; using JiShe.CollectBus.FreeRedisProvider;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
@ -385,16 +386,18 @@ namespace JiShe.CollectBus.RedisDataCache
bool descending = true) bool descending = true)
where T : DeviceCacheBasicModel where T : DeviceCacheBasicModel
{ {
// 参数校验 // 参数校验增强
if (string.IsNullOrWhiteSpace(redisHashCacheKey) || if (string.IsNullOrWhiteSpace(redisHashCacheKey) || string.IsNullOrWhiteSpace(redisZSetScoresIndexCacheKey))
string.IsNullOrWhiteSpace(redisZSetScoresIndexCacheKey))
{ {
_logger.LogError("参数异常: HashKey或ZSetKey为空"); _logger.LogError($"{nameof(GetAllPagedData)} 参数异常,-101");
return null; return null;
} }
if (pageSize < 1 || pageSize > 10000) if (pageSize < 1 || pageSize > 10000)
throw new ArgumentException("分页大小应在1-10000之间"); {
_logger.LogError($"{nameof(GetAllPagedData)} 分页大小应在1-10000之间-102");
return null;
}
var luaScript = @" var luaScript = @"
local command = ARGV[1] local command = ARGV[1]
@ -504,7 +507,7 @@ return {#result_members, result_members, result_scores, hash_data}";
var hasNext = validItems.Count > pageSize; var hasNext = validItems.Count > pageSize;
var actualItems = hasNext ? validItems.Take(pageSize) : validItems; var actualItems = hasNext ? validItems.Take(pageSize) : validItems;
// 修正分页锚点索引 //分页锚点索引
decimal? nextScore = null; decimal? nextScore = null;
string nextMember = null; string nextMember = null;
if (hasNext && actualItems.Any()) if (hasNext && actualItems.Any())