Python-Firebase侦听器实现 [英] Python-Firebase listener implementation

查看:42
本文介绍了Python-Firebase侦听器实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以让您积极地使用Python侦听Firebase数据库?

Is there a way where you can actively have a listener for a Firebase Database in Python?

例如,我在数据库中有一个节点 user ,我希望能够主动侦听用户立即发生的任何更改并立即对其进行更改.

For instance, I have a node user in the database, I want to be able to actively listen for any changes that immediately happens for a user and immediately make changes on it.

现在,我只是在使用for循环.就我而言,我为用户提供了类似 sync_state 之类的整数值 3 .会话结束后,它更改为 4 .我想为该用户更新值.

For now, I'm just using a for-loop. In my case, I have something like sync_state for user with the integer value 3. It gets changed to 4 when the session has been ended, I want to update value for that user.

现在,我定期运行for循环,但是当我的数据库中有很多用户时,它将在将来效率不高.与使用Node.JS相比,有没有办法以python- ish 的方式做到这一点?

Right now, I run the for-loop periodically, but it won't be efficient in the future when I have a lot of users in my database. Is there a way to do this in a python-ish way than using Node.JS?

推荐答案

您可以使用Firebase的REST流API:

You can use Firebase's REST Streaming API: https://firebase.google.com/docs/database/rest/retrieve-data#section-rest-streaming.

介绍该API的博客文章包括一些Python示例: https://firebase.googleblog.com/2014/03/announcing-streaming-for-firebase-rest.html

The blog post that introduced that API, includes some samples for Python: https://firebase.googleblog.com/2014/03/announcing-streaming-for-firebase-rest.html

有些包装该API的Python库: https://www.google.nl/webhp#q = firebsae%20python%20streaming

There are some Python libraries that wrap that API: https://www.google.nl/webhp#q=firebsae%20python%20streaming

这篇关于Python-Firebase侦听器实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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