#! /usr/bin/python
#coding=utf-8
import sys
import redis
reload(sys)
sys.setdefaultencoding('utf-8')
r = redis.StrictRedis(host='127.0.0.1',port=6380,password='foobared')
for i in range(20):
r.set('key_'+str(i) , i)
#print(r.get('key_'+str(i)))
#for k in r.scan_iter('key_*') :
# print k+":",r.get(k)
start_pos=0
cnt=5
while True:
scanResult = r.scan(cursor=start_pos, match='key_*',count=cnt)
end_pos, res_list= scanResult
if len(res_list) >=0:
for i in range(len(res_list)):
print( res_list[i],r.get(res_list[i]) )
# r.delete(*res_list)
if end_pos==0:
break
start_pos=end_pos
r.close()