1

阅读有关如何在此处进行排序集的文档很有趣。

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 数据库中有大量数据,此操作会变得昂贵且运行缓慢吗?

4

0 回答 0