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?
Use SCAN command:
>>> import redis
>>> r = redis.Redis()
>>> for x in r.scan_iter('dummy*'):
... print(x)
...
b'dummy3'
b'dummy2'
b'dummy1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With