Zep
Zep

Reputation: 46

How I get ALL keys in Redis? 1+ billion keys in total

1+ billion keys in redis.
Now I want get ALL the keys in python.

partkeys = redisclient.keys("abcd*")

will be ok.
But

keys = redisclient.keys("ab*")

will raise ResponseError.

redis.exceptions.ResponseError: keys err

And

keys = redisclient.keys("*")

will raise a ConnectionError.
redis.exceptions.ConnectionError: Error 111 connecting demo.abcd.com:6397. Connection refused.

Any help?

Upvotes: 2

Views: 8313

Answers (2)

danius
danius

Reputation: 2764

I suppose you use py-redis, use scan_iter, then:

for k in redisclient.scan_iter(match='*'):
     # Do something with k
     # ...

As others noted, SCAN is only available since Redis 2.8.0

Upvotes: 2

FGRibreau
FGRibreau

Reputation: 7229

Use then SCAN command to loop over your key set. Using KEYS is always a bad idea. Note that SCAN is only available since Redis 2.8.0.

Upvotes: 4

Related Questions