如何在Azure表中获得最高价值 [英] How to get the highest value in Azure Table

查看:58
本文介绍了如何在Azure表中获得最高价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪个用户在群组中发送了更多消息.

I want to know which user sent more messages in a group.

public class UserEntity : TableEntity
{
    public UserEntity()
    {

    }

    public UserEntity(string chatId, string userId) 
        : base(chatId, userId)
    {
    }

    public int Name { get; set; }
    public int MessagesCount { get; set; }
}

当我收到一条新消息时,会增加该用户的 MessagesCount .一天结束时,我怎么知道哪个具有最高的 MessagesCount ?

When I receive a new message, I increase MessagesCount of that user. At the end of the day how can I know which one has the highest MessagesCount?

谢谢.

推荐答案

一天结束时,我怎么知道哪一个具有最高的MessagesCount?

At the end of the day how can I know which one has the highest MessagesCount?

您可以按 MessagesCount 进行排序,并获得具有最高MessagesCount的用户.然后,您可以在预定的WebJob中执行以下查询并缓存结果,然后可以从程序的缓存中获取结果,而不是从表存储中查询结果.

You can sort by MessagesCount and get the user who has the highest MessagesCount. And you can execute the following query in a scheduled WebJob and cache the result, and then you can get result from the cache in your program instead of querying the result from Table storage.

TableQuery<UserEntity> query = new TableQuery<UserEntity>();

UserEntity user = table.ExecuteQuery(query).OrderBy(a => a.MessagesCount).LastOrDefault();

此外,您的要求类似于实施记分板,如果可能的话,每次更新用户的信息时,您都可以将顶级1 用户信息存储在单独的实体中.MessagesCount,您可以将当前用户的MessagesCount与该实体进行比较,如果当前用户的MessagesCount更高,则可以更新该实体.这样,您可以通过点查询查询该(一个)实体,以获取具有最高MessagesCount的用户.

Besides, your requirements is similar to implement a scoreboard, if possible, you can store top-one user information in a separate entity, every time when you update user’s MessagesCount, you can compare current user’s MessagesCount with that entity and update that entity if current user’s MessagesCount is higher. In this way, you can query that (one) entity via point query to get the user who has the highest MessagesCount.

这篇关于如何在Azure表中获得最高价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆