简短回答
虽然get
and join
的方法group
应该返回相同的结果,get
实现一些缓存,并且可能会更有效,具体取决于您使用的后端。除非你确实需要使用join
对于某些边缘情况,您应该使用get
.
长答案
这是get
芹菜的做法ResultSet
类其中GroupResult
阶级延伸。
def get(self, timeout=None, propagate=True, interval=0.5,
callback=None, no_ack=True, on_message=None):
"""See :meth:`join`
This is here for API compatibility with :class:`AsyncResult`,
in addition it uses :meth:`join_native` if available for the
current result backend.
"""
if self._cache is not None:
return self._cache
return (self.join_native if self.supports_native_join else self.join)(
timeout=timeout, propagate=propagate,
interval=interval, callback=callback, no_ack=no_ack,
on_message=on_message,
)
我们看到的第一件事是文档字符串告诉我们查看join
记录方法。这立即表明这些方法非常相似。
看着对方的身体get
方法中,我们可以看到它首先检查缓存的值,如果已设置则返回该值。如果没有找到缓存值,get
将调用join
or the join_native
方法取决于后端是否支持本机连接。如果你找到它的格式return
声明有点令人困惑,这本质上是同一件事:
if self.supports_native_join:
return self.join_native(timeout=timeout,
propagate=propagate,
interval=interval,
callback=callback,
no_ack=no_ack,
on_message=on_message)
else:
return self.join(timeout=timeout,
propagate=propagate,
interval=interval,
callback=callback,
no_ack=no_ack,
on_message=on_message)
的文档字符串join
方法有这个说法。
对于结果存储后端来说,这可能是一项昂贵的操作,必须
诉诸轮询(例如数据库)。你应该考虑使用join_native
如果你的后端支持的话。
So you should正在打电话join_native
代替join
如果你的后端支持的话。但为什么要费尽心思有条件地调用其中一个呢?get
为您总结了这个逻辑吗?只需使用get
反而。