set。求交集,并集。可?
的确用 Set
就可以,开始时想复杂了
public async Task<int[]> GetCachedPostIds(int blogId, int categoryId)
{
var cacheKey = CacheKeyManager.PostToCategoryMap(blogId, categoryId);
if (await _redis.ExistsAsync(cacheKey))
{
return await _redis.SetMembersAsync<int>(cacheKey);
}
return await GetPostIds(blogId, categoryId);
}
private async Task<int[]> GetPostIds(int blogId, int categoryId)
{
var cacheKey = CacheKeyManager.PostToCategoryMap(blogId, categoryId);
var postIds = (await GetPostToCategoryIds(blogId, categoryId, false)).ToArray();
await _redis.SetAddAllAsync(cacheKey, CommandFlags.None, postIds);
await _redis.UpdateExpiryAsync(cacheKey, TimeSpan.FromHours(3));
return postIds;
}
Categorize values in Redis... should I use sets or keys?
– dudu 4个月前