In the documentation, it strongly discourages the use of .keys()
in a production environment. What would be an alternative to the following:
r = Redis()
keys = r.keys('RT*')
for key in keys:
do_something()
So yes, SCAN is blocking, but it's usually not a big deal, and is only blocking when Redis is actually processing the command.
Redis is an open-source, in-memory key-value data store. A key-value data store is a type of NoSQL database in which keys serve as unique identifiers for their associated values. Any given Redis instance includes a number of databases, each of which can hold many different keys of a variety of data types.
Keys in Redis are all strings, so it doesn't really matter what kind of value you pass into a client.
SCAN
is the recommended alternative for production usage.
redis-py includes a convenient SCAN
iterator for that purpose, so what you can do is:
r = Redis()
for key in r.scan_iter(match='RT*'):
print(key) # or do something
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