Reputation: 5706
I need all the keys in redis matching a given pattern : *_xyz_*
, then I get all their values by following python code:-
def get_keys(self,pattern):
self.r_prod.keys(pattern);
keys = self.r_prod.execute();
for i in keys[0]:
self.r_prod.get(i);
return self.r_prod.execute();
Now keys
is pretty huge to hold all in the memory. So, I am wondering is there any way to paginate keys call for a certain limit?
Upvotes: 4
Views: 3591
Reputation: 4715
Use SCAN command:
>>> import redis
>>> r = redis.Redis()
>>> for x in r.scan_iter('dummy*'):
... print(x)
...
b'dummy3'
b'dummy2'
b'dummy1'
Upvotes: 7