Junior — Middle
Kuidas täielikult puhastada kõik andmed Redis tabelist?
sobes.tech AI
Vastus AI-lt
To completely delete all data from a table (set of keys) in Redis, you can use the DEL command to delete individual keys or the FLUSHDB command to clear the entire database.
If by "table" you mean a set of keys with a common prefix, you can do the following:
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
# Get all keys with the desired prefix
keys = r.keys('prefix:*')
if keys:
r.delete(*keys)
If you want to clear the entire Redis database:
r.flushdb()
The flushdb() command will delete all keys from the current Redis database.