有没有一种方法可以让您在 Python 中主动拥有 Firebase 数据库的监听器?
例如,我在数据库中有一个节点 user
,我希望能够主动监听用户立即发生的任何更改,并立即对其进行更改。
目前,我只使用 for 循环。在我的例子中,对于整数值 3
的用户,我有类似 sync_state
的东西。当 session 结束时,它会更改为 4
,我想更新该用户的值。
现在,我定期运行 for 循环,但将来当我的数据库中有很多用户时,它就不会高效了。有没有比使用 Node.JS 更符合 pythonish 的方式来做到这一点?
最佳答案
您可以使用 Firebase 的 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
有一些包装该 API 的 Python 库:https://www.google.nl/webhp#q=firebsae%20python%20streaming
关于Python-Firebase 监听器实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40984433/