I am using the redis scan to iterate over the key in my redis DB.This is the code i am using
#example :1
start_cursor=0
r=redis.StrictRedis(host='localhost',port=6379)
cur, keys = r.scan(cursor=start_cursor, match='*', count=3)
records=len(keys)
values=[]
values.extend(i for i in keys)
print cur,records,values
while cur != 0:
cur, keys = r.scan(cursor=cur, match='*', count=3)
records+=len(keys)
data = r.mget(keys=keys)
values.extend(i for i in keys)
print cur, len(keys),values
print "Total records scanned :{}".format(records)
My DB has following values in the format (key,values) (1,1)(2,2)(3,3)(4,4)(5,5)
When I am scanning my records with
start_cursor=0
I am getting the following records
scan #=>Cursor,new records,all records
scan #1 =>5,3,['1', '2', '5']
scan #2 =>0,2,['1', '2', '5', '3', '4']
Total Records scanned :5
when I am starting the scanning with my cursor number from scan #1 say(5).I am getting the records from the scan #2 in my example 1
Example : 2
start_cursor=5
scan #=>Cursor,new records,all records
scan #1 =>0 2 ['3', '4']
Total Records scanned :2
Everything is fine upto now.when I insert four more new data say (6,6) (7,7) (8,8) (9,9) and start the scanning the data with start_cursor = 5
same as example :2
I am missing some of the data say (6) is missed here.
Example : 3
start_cursor=5
scan #=>Cursor,new records,all records
scan #1 =>3 3 ['3', '4', '9']
scan #1 =>0 2 ['3', '4', '9', '7', '8']
Total Records scanned :5
Whether redis scan will scan data inserted after scan operation started ? If not is there is any other way to achieve this?
Thanks in advance!!