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.