遍历redis数据库中有以格式为prefix_*的按照key-value方式存储的key,并打印其值.
遍历使用SCAN,因为KEYS PREFIX_*可能会造成Redis长时间阻塞。
查询使用pipeline减少交互,提高效率。
import redis import hiredis pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0) r = redis.Redis(connection_pool=pool) pipe = r.pipeline() pipe_size = 100000 len = 0 key_list = [] for key in r.scan_iter(match='PREFIX_*', count=100000): key_list.append(key) pipe.get(key) if len < pipe_size: len += 1 else: 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
附上其他网页的代码,参考下吧
# filename itertaorfilefolder
import os
import os.path
filePath = raw_input('Enter filepath : ')
#遍历文件夹
#三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字
for parent ,dirnames , filenames in os.walk(filePath):
#输出文件夹信息
for dirname in dirnames:
print 'parent is :'+parent
print 'dirname is '+ 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 'the file size is : %.3f MB' %(filesize)
#删除大于50m的文件
if filesize > 50:
delete = raw_input(' are you sure to delete ?')
if delete == 'yes':
os.remove(currentPath)以上所述就是本文的全部内容了,希望大家能够喜欢。
采用HttpClient向服务器端action请求数据,当然调用服务器端方法获取数据并不止这一种。WebService也可以为我们提供所需数据,那么什么是webService呢?,它是一种基于SAOP协议的远程调用标准,通过webservice可以将不同操作系统平台,不同语言,不同技术整合到一起。 实现Android与服务器端数据交互,我们在PC机器java客户端中,需要一些库,比如XFire,Axis2,CXF等等来支持访问WebService,但是这些库并不适合我们资源有限的android手机客户端,
0
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号