[程序员] 请问 Python 操作 Redis 写入数据每秒 5W 算正常么?

代码如下,使用了 pipeline,10W 数据执行下来要 2s,这个算是正常速度么?请问还有啥跑更快的办法么?


from datetime import datetime
from redis import StrictRedis
redis = StrictRedis(host='redis', port=6379, db=0) def test_redis(count): pipeline = redis.pipeline() process_start = datetime.now().timestamp() for value in range(1, count): user_key = 'user:id:' + str(value) pipeline.set(user_key, 'bar') pipeline.execute() process_elapsed = round(datetime.now().timestamp() - process_start, 2) print("\nDone ({}s).\n".format(process_elapsed)) test_redis(100000)

发表回复

您的电子邮箱地址不会被公开。