在线GAE应用程序用户 [英] Online GAE Application User

查看:85
本文介绍了在线GAE应用程序用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何知道用户当前是否已登录到您的Google App Engine应用程序?

How to know if a user is currently logged-in in your Google App Engine application?

该应用程序允许其用户浏览其他用户的个人资料。如果查看的个人资料也在使用或登录应用程序,我想通知,查看的个人资料是联机。

The application allow its users to browse other users' profile. If the viewed profile is also using or logged-in in the application, i want a notification that the viewed profile is online.

如何达到这个要求?

推荐答案

您可以像Gaël建议的那样使用 Channel API 来跟踪这个,但它可能是过度的。如果你想要走这条路,只要听听连接的&断开连接的消息,并更新数据库中指示用户已登录的字段。

You could, as Gaël suggests, use the Channel API to track this, but it's probably overkill. If you wanted to go that route, just listen for the connected & disconnected messages, and update a field in the db that indicates that the user is signed in.

更便宜的路线可能是更新用户记录中的字段,就像上次用户请求一个页面。如果自用户最后一次请求页面以来已超过 n 分钟,则假定它们已注销。事实上,你甚至可以在memcache中使用从userid到最后访问时间的地图来做到这一点。

A less expensive route might be to just update a field in your user's record that's something like "last time this user requested a page." If it's been more than n minutes since the last time the user requested a page, assume they're signed out. Indeed, you could even do this in memcache with a map from userid to last access time.

它取决于你想要对登录信息做什么:如果您只想给出一般用户是否在线或有多少用户在线,则使用数据存储或memcache解决方案可能是好的。另一方面,如果你想反映用户的存在,以便他们可以响应例如。 IMs,那么你可能会想要Channel API,所以你可以立即向他们发送消息。

It comes down to what you want to do with the "signed in" information: if you just want to give a general sense of whether a user's around, or how many users are online, using the datastore or memcache solution is probably good. On the other hand, if you want to reflect the user's presence so they can respond to eg. IMs, then you'll probably want the Channel API anyway so you can immediately deliver messages to them.

这篇关于在线GAE应用程序用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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