Redis批量寫入與單key寫入性能對比

數據量 100萬 數據內容 64字節隨機字符串python

單條寫入: 耗時:141秒 速度:7052/s 代碼:code

<!-- lang: python -->
st = time.time()
for x in datalist:
r.sadd('settest',x)
print "cost:%s speed:%s/s "%(time.time()-st,scale/(time.time()-st))

批量寫入 : 耗時:31秒 速度:31599/s 代碼:ip

<!-- lang: python -->
pl = r.pipeline()
st = time.time()
count=0
for x in datalist:
    pl.sadd('settest',x)
    count+=1
    if count>50000:
        count=0
        pl.execute()
 pl.execute()
 print "cost:%s speed:%s/s "%(time.time()-st,scale/(time.time()-st))
相關文章
相關標籤/搜索