3

请问 Python 操作 Redis 写入数据每秒 5W 算正常么?

 2 years ago
source link: https://www.v2ex.com/t/806138
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

请问 Python 操作 Redis 写入数据每秒 5W 算正常么?

  Phishion · 1 天前 · 1047 次点击

代码如下,使用了 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)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK