redis緩存遷移 如何快速?gòu)膍ysql數(shù)據(jù)庫(kù)導(dǎo)大量數(shù)據(jù)到redis?
如何快速?gòu)膍ysql數(shù)據(jù)庫(kù)導(dǎo)大量數(shù)據(jù)到redis?導(dǎo)入redisimport timeredis=雷迪斯。雷迪斯(主機(jī)=“l(fā)ocalhost”,端口=6379,數(shù)據(jù)庫(kù)=0)秒時(shí)間=時(shí)間。時(shí)間()帶re
如何快速?gòu)膍ysql數(shù)據(jù)庫(kù)導(dǎo)大量數(shù)據(jù)到redis?
導(dǎo)入redisimport timeredis=雷迪斯。雷迪斯(主機(jī)=“l(fā)ocalhost”,端口=6379,數(shù)據(jù)庫(kù)=0)秒時(shí)間=時(shí)間。時(shí)間()帶redis.pipeline公司()作為管道:管道.多()對(duì)于索引,item in item in enumerate(qset):#qset是查詢的結(jié)果集,tkey=item[“ID”]-tvalue=item[“name”]-tret=管道.sadd(鍵,值) 如果索引%1000==0: print“Now cnt:%d”%(i 1) 管道.執(zhí)行() 管道.多()打印“執(zhí)行…”管道.執(zhí)行()時(shí)間=時(shí)間。時(shí)間()
上面省略了MySQL查詢代碼,它是通過(guò)鍵值對(duì)來(lái)描述的