Python-redis-pipe file

Source: Internet
Author: User

Redis Import data is a headache, involving tens of millions of, import or very time-consuming, through the generation of pipe files more quickly.

The python3.6.1 version runs in a Linux environment

    With open ("Data1", "W") as F: for        D in data:            k = d["key"]            v = d[' value ')            f.write (' *3\r\n$3\r\nset\r\n$%d\ r\n%s\r\n$%d\r\n%s\r\n '% (len (bytes (k, ' Utf-8 ')), K, Len (bytes (v, ' utf-8 ')), V))

  

python2.7

    For line in Lines:line=line.strip (' \ n ')        jsonline = json.loads (line)        province = jsonline["province"]if province = = Henan:            key = jsonline["Company_Name"]            k = key.encode (' utf-8 ')    v = line            print ' *3\r\n$3\r\nset\r\n$% d\r\n%s\r\n$%d\r\n%s\r\n '% (Len (k), K, Len (v), V),

  

127.0.0.1:6379> Select 10ok127.0.0.1:6379[10]> dbsize (integer) 2907521

  

Python-redis-pipe file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.