Python implementation traverses the database and gets the value of the key

Source: Internet
Author: User
Traverse the Redis database with a prefix_*-formatted key stored as Key-value and print its value.

Traverse using scan because the keys prefix_* may cause Redis to block for a long time.
Queries use pipeline to reduce interactions and increase efficiency.

Import Redisimport Hiredispool = Redis. ConnectionPool (host= ' 127.0.0.1 ', port=6379, db=0) R = Redis. Redis (connection_pool=pool) pipe = R.pipeline () pipe_size = 100000len = 0key_list = []for key in R.scan_iter (Match= ' prefix_ * ', count=100000): Key_list.append (key) Pipe.get (key) If Len < Pipe_size:len + = 1else:for (k, v) in zip (key_list, pipe. Execute ()): Print k, v len = 0 key_list = []for (k, v) in Zip (Key_list, Pipe.execute ()): Print K, V

Attach the code of other pages, and refer to the following.

# filename itertaorfilefolder import os import os.pathfilepath = Raw_input (' Enter filepath: ') #遍历文件夹 #三个参数: Returns 1 respectively. Parent Directory 2. All Folder name (without path) 3. All file names for the parent, Dirnames, filenames in Os.walk (filePath):   #输出文件夹信息 for   dirname in dirnames:
  
   print ' parent is: ' +parent     print ' dirname was ' + dirname   #输出文件信息 for   filename in filenames:     print ' Parent is: ' +parent     print ' filename is: ' + filename     #输出文件路径信息     currentpath = Os.path.join (parent,filename)     print ' The fulll name of the file is: ' + currentpath     filesize = os.path.getsize (currentpath)/1024/1024     print ' th  E File size is:%.3f MB '% (filesize)     #删除大于50m的文件     if filesize >:       delete = Raw_input (' Was you sure to Delete? ')       if delete = = ' Yes ':         os.remove (Currentpath)
  

The above mentioned is the whole content of this article, I hope you can like.

  • 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.