【发布时间】:2021-05-14 06:13:15
【问题描述】:
现在我正在使用 python(Python 3) redis 客户端将元素添加到 redis 流中,这是 lib 的依赖项:
redis~=5.0.3
然后这是我使用 Python 将元素写入 redis 的代码:
def push_message_to_stream(article):
try:
message = {
"id": article.id,
"sub_source_id": article.sub_source_id
}
#
# Redis did not remove the ack message automatic
# when the element is full, it remove the oldest
#
redis_client.xadd(name=article_stream_name, fields=message, maxlen=10)
# redis_client.xgroup_create(name=article_stream_name, groupname=article_group_name)
# redis_client.publish(channel=article_stream_name, message="hello world!")
except Exception as e:
logger.error("write stream error:", e)
该元素可以成功写入redis,但是在我将maxlen的参数添加到10之后,当我检查redis中的流元素时,流中仍然有90多个元素,我猜测可能是redis使用旧的创建者配置,然后我尝试删除流并重新创建它,但仍然在这种情况下,我在哪里做错了?为什么maxlen参数没有生效?
【问题讨论】: