[英]Python-Firebase listener implementation
Is there a way where you can actively have a listener for a Firebase Database in Python? 有没有办法在Python中主动拥有Firebase数据库的监听器?
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. 例如,我在数据库中有一个节点
user
,我希望能够主动监听用户立即发生的任何更改,并立即对其进行更改。
For now, I'm just using a for-loop. 现在,我只是使用for循环。 In my case, I have something like
sync_state
for user with the integer value 3
. 就我而言,我有一个类似
sync_state
的用户,其整数值为3
。 It gets changed to 4
when the session has been ended, I want to update value for that user. 当会话结束时,它会更改为
4
,我想更新该用户的值。
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. 现在,我定期运行for循环,但是如果我的数据库中有很多用户,将来效率会不高。 Is there a way to do this in a python- ish way than using Node.JS?
有没有一种方法比使用Node.js的一个python- 十岁上下的方式做到这一点?
You can use Firebase's REST Streaming API: https://firebase.google.com/docs/database/rest/retrieve-data#section-rest-streaming . 您可以使用Firebase的REST Streaming API: https : //firebase.google.com/docs/database/rest/retrieve-data#section-rest-streaming 。
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 : //firebase.googleblog.com/2014/03/announcing-streaming-for-firebase-rest.html
There are some Python libraries that wrap that API: https://www.google.nl/webhp#q=firebsae%20python%20streaming 有一些Python库包装该API: https : //www.google.nl/webhp#q = firebsae%20python%20streaming
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.