@
RedisMasterNode 试了一下读写 10 万条 10 个字段在 15 秒以内,1 万条在 3 秒以内,完全可以接受。反正每天才一次,而且短期不会有 1 万个用户。就这么搞算了。估计放到云上要快些,现在是在树莓派 4 上测试的。
t0=time.time()
pool = redis.ConnectionPool(host='192.168.31.115', port=6379, db=0,decode_responses=True)
r = redis.Redis(connection_pool=pool)
with r.pipeline(transaction=False) as p:
for n in range(100000):
k=f"client_{n}"
v={"k1":"v1","k2":"v2","k3":"v3","k4":"v4","k5":"v5","k6":"v6","k7":"v7","k8":"v8","k9":"v9","k10":"v10"}
p.hmset(k,v)
t1=time.time()
print(f"set in pip in {t1-t0} secs")
p.execute()
t2=time.time()
print(f"pipe exec in {t2-t1} secs")
print(f"total write in {t2-t0} secs")
t0=time.time()
with r.pipeline(transaction=False) as p:
for n in range(100000):
k=f"client_{n}"
p.hgetall(k)
t1=time.time()
print(f"read in pip in {t1-t0} secs")
result=p.execute()
t2=time.time()
print(f"pipe exec in {t2-t1} secs")
print(f"total read in {t2-t0} secs")
<ipython-input-71-ba09b5712492>:9: DeprecationWarning: Pipeline.hmset() is deprecated. Use Pipeline.hset() instead.
p.hmset(k,v)
set in pip in 0.4727442264556885 secs
pipe exec in 14.024574041366577 secs
total write in 14.497318267822266 secs
read in pip in 0.18680548667907715 secs
pipe exec in 12.720657110214233 secs
total read in 12.90746259689331 secs