阅读有关如何进行排序集here的文档很有意思。
public void Show_a_TagCloud()
{
//Get strongly-typed clients
using (var redisBlogPosts = redisClient.GetTypedClient<BlogPost>())
{
var newIncomingBlogPosts = redisBlogPosts.GetAll();
foreach (var newBlogPost in newIncomingBlogPosts)
{
//For every tag in each new blog post, increment the number of times each Tag has occurred
newBlogPost.Tags.ForEach(x =>
redisClient.IncrementItemInSortedSet("urn:TagCloud", x, 1));
}
//Show top 5 most popular tags with their scores
var tagCloud = redisClient.GetRangeWithScoresFromSortedSetDesc("urn:TagCloud", 0, 4);
Debug.WriteLine(tagCloud.Dump());
}
/* Output:
[
[
NoSQL,
4
],
[
Scalability,
2
],
[
JSON,
2
],
[
Redis,
1
],
[
Raven,
1
],
]
*/
}
要执行诸如热门项目列表之类的任务,您必须先调用redistypedclient.GetAll()来检索所有记录,然后使用for循环来标记流行度。我的问题是,如果您的redis数据库中有大量数据,此操作会变得昂贵且运行缓慢吗?