Tornado 异步请求中的多个数据库调用
我目前正在使用 Tornado 和 asyncmongo 创建一个访问 mongodb 的网站。一切都工作得很好,除了当我需要在对处理程序的单个请求中向 mongodb 发出多个请求时。我想保持所有数据库调用异步,这样服务器上就不会阻塞。
我怎样才能做到这一点?在某些情况下,我需要从多个集合中检索不同的文档。有时我还需要在第二个查询中使用从第一个查询中检索到的数据,例如外键。当我渲染模板时,我还需要来自两个请求的数据。
谢谢!
I am currently using Tornado and asyncmongo to create a website that accesses a mongodb. Everything is working great except when I need to make multiple requests to mongodb within in a single request to my handler. I would like to keep all my database call asynchronous so that there is no blocking on the server.
How can I accomplish this? There are several cases in which I need to retrieve different documents from multiple collections. I also sometimes need to use data that I retrieved from my first query in the second such as a foreign key. I will also need the data from both requests when I render my template.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个请求是否都会触发不同的回调?
例如(我没有测试这个,而且我不熟悉 asyncmongo,所以它可能包含错误):
Have each request trigger a different callback?
e.g. (I didn't test this, and I'm not familiar with asyncmongo, so it probably contains errors):