现在我正在使用 Python(Python 3
) redis 客户端向 redis 流添加元素,这是该库的依赖项:
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)
在加入maxlen
参数之前,该元素可以成功写入Redis。但是,当我将maxlen
参数设置为10后,在Redis检查流元素时,它仍然有90多个元素。我猜可能是Redis使用了旧的创建者配置。于是我尝试删除流并重新创建它,但仍处于这种情况。我做错了什么?为什么maxlen
参数没有产生任何效果?