Redis Key Deletion by Pattern

  • Share this:

Code introduction


This function uses Redis' keys method to find keys that match a specific pattern, then uses the delete method to remove these keys. This is usually used to clean up all keys that match a specific pattern.


Technology Stack : redis

Code Type : Function

Code Difficulty : Intermediate


                
                    
        def random_key_delete(r, pattern):
            keys = r.keys(pattern=pattern)
            for key in keys:
                r.delete(key)
        
                        
              
Tags: