Answer the question
In order to leave comments, you need to log in
What is the safest way to remove more than 2KK keys from Redis?
Hello! Tell me, it's very necessary.
Let's say there is a database, you need to delete data by prefix (standard).
$keys = $this->redis->keys($this->_prefix . '*');
$this->redis->del($keys);
Answer the question
In order to leave comments, you need to log in
Since 3.0, it is recommended to use tags for this. Keys hash tags
In your case - they should be used instead of a prefix.
Key names should look something like this - {user1000}.following, where user1000 is the tag.
KEYS by tag will not check all keys in the database, i.e. the complexity will be orders of magnitude less than O(N)
And as a bonus - it will be compatible with redis-cluster
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question