2025-04-16 17:36:46 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Models;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Application.Contracts
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 数据缓存服务接口
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public interface IRedisDataCacheService
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 单个添加数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
/// <param name="redisSetIndexCacheKey">Set索引缓存Key</param>
|
|
|
|
|
|
/// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
/// <param name="data">待缓存数据</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
Task InsertDataAsync<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisSetIndexCacheKey,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
T data) where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量添加数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
/// <param name="redisSetIndexCacheKey">Set索引缓存Key</param>
|
|
|
|
|
|
/// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
/// <param name="items">待缓存数据集合</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
Task BatchInsertDataAsync<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisSetIndexCacheKey,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
IEnumerable<T> items) where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除缓存信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
/// <param name="redisSetIndexCacheKey">Set索引缓存Key</param>
|
|
|
|
|
|
/// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
/// <param name="data">已缓存数据</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
Task RemoveCacheDataAsync<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisSetIndexCacheKey,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
T data) where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改缓存信息,映射关系未发生改变
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
/// <param name="redisSetIndexCacheKey">Set索引缓存Key</param>
|
|
|
|
|
|
/// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
/// <param name="newData">待修改缓存数据</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
Task ModifyDataAsync<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisSetIndexCacheKey,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
T newData) where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改缓存信息,映射关系已改变
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
/// <param name="redisSetIndexCacheKey">Set索引缓存Key</param>
|
|
|
|
|
|
/// <param name="oldMemberId">旧的映射关系</param>
|
|
|
|
|
|
/// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
/// <param name="newData">待修改缓存数据</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
Task ModifyDataAsync<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisSetIndexCacheKey,
|
|
|
|
|
|
string oldMemberId,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
T newData) where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 通过集中器与表计信息排序索引获取数据
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <typeparam name="T"></typeparam>
|
|
|
|
|
|
///// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
///// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
///// <param name="pageSize">分页尺寸</param>
|
|
|
|
|
|
///// <param name="lastScore">最后一个索引</param>
|
|
|
|
|
|
///// <param name="lastMember">最后一个唯一标识</param>
|
|
|
|
|
|
///// <param name="descending">排序方式</param>
|
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
|
//Task<BusCacheGlobalPagedResult<T>> GetPagedData<T>(
|
|
|
|
|
|
//string redisHashCacheKey,
|
|
|
|
|
|
//string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
//IEnumerable<int> focusIds,
|
|
|
|
|
|
//int pageSize = 10,
|
|
|
|
|
|
//decimal? lastScore = null,
|
|
|
|
|
|
//string lastMember = null,
|
|
|
|
|
|
//bool descending = true)
|
|
|
|
|
|
//where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-17 11:29:26 +08:00
|
|
|
|
/// 通过ZSET索引获取数据,支持10万级别数据处理,控制在13秒以内。
|
2025-04-16 17:36:46 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
/// <param name="redisHashCacheKey">主数据存储Hash缓存Key</param>
|
|
|
|
|
|
/// <param name="redisZSetScoresIndexCacheKey">ZSET索引缓存Key</param>
|
|
|
|
|
|
/// <param name="pageSize">分页尺寸</param>
|
|
|
|
|
|
/// <param name="lastScore">最后一个索引</param>
|
|
|
|
|
|
/// <param name="lastMember">最后一个唯一标识</param>
|
|
|
|
|
|
/// <param name="descending">排序方式</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
Task<BusCacheGlobalPagedResult<T>> GetAllPagedData<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
int pageSize = 1000,
|
|
|
|
|
|
decimal? lastScore = null,
|
|
|
|
|
|
string lastMember = null,
|
|
|
|
|
|
bool descending = true)
|
|
|
|
|
|
where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-17 11:29:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 优化后的分页获取方法(支持百万级数据)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
Task<BusCacheGlobalPagedResult<T>> GetAllPagedDataOptimized<T>(
|
|
|
|
|
|
string redisHashCacheKey,
|
|
|
|
|
|
string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
int pageSize = 1000,
|
|
|
|
|
|
decimal? lastScore = null,
|
|
|
|
|
|
string lastMember = null,
|
|
|
|
|
|
bool descending = true) where T : DeviceCacheBasicModel;
|
|
|
|
|
|
|
2025-04-16 17:36:46 +08:00
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 游标分页查询
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <param name="redisZSetScoresIndexCacheKey">排序索引ZSET缓存Key</param>
|
|
|
|
|
|
///// <param name="pageSize">分页数量</param>
|
|
|
|
|
|
///// <param name="startScore">开始索引</param>
|
|
|
|
|
|
///// <param name="excludeMember">开始唯一标识</param>
|
|
|
|
|
|
///// <param name="descending">排序方式</param>
|
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
|
//Task<(List<string> Members, bool HasNext)> GetPagedMembers(
|
|
|
|
|
|
// string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
// int pageSize,
|
|
|
|
|
|
// decimal? startScore,
|
|
|
|
|
|
// string excludeMember,
|
|
|
|
|
|
// bool descending);
|
|
|
|
|
|
|
2025-04-17 11:29:26 +08:00
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 批量获取指定分页的数据
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <typeparam name="T"></typeparam>
|
|
|
|
|
|
///// <param name="redisHashCacheKey">Hash表缓存key</param>
|
|
|
|
|
|
///// <param name="members">Hash表字段集合</param>
|
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
|
//Task<Dictionary<string, T>> BatchGetData<T>(
|
|
|
|
|
|
// string redisHashCacheKey,
|
|
|
|
|
|
// IEnumerable<string> members)
|
|
|
|
|
|
// where T : DeviceCacheBasicModel;
|
2025-04-16 17:36:46 +08:00
|
|
|
|
|
2025-04-17 11:29:26 +08:00
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 获取下一页游标
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <param name="redisZSetScoresIndexCacheKey">排序索引ZSET缓存Key</param>
|
|
|
|
|
|
///// <param name="lastMember">最后一个唯一标识</param>
|
|
|
|
|
|
///// <param name="descending">排序方式</param>
|
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
|
//Task<decimal?> GetNextScore(
|
|
|
|
|
|
// string redisZSetScoresIndexCacheKey,
|
|
|
|
|
|
// string lastMember,
|
|
|
|
|
|
// bool descending);
|
2025-04-16 17:36:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|