Now I am using python(Python 3) redis client to add element into redis stream, this is the dependencies of the lib:
redis~=5.0.3
and then this is my code to write element into redis using Python:
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)
the element could write into redis successfully, but after I add parameter of maxlen to 10, when I check the stream element in redis, it still has more than 90+ element in the stream, I gusses maybe the redis using old creator config,then I tried delete the stream and recreated it but still in this situation, where am I doing wrong? why the maxlen parameter did not take any effect?