The method is as follows:
# redis connection, chain refers to the test environment Redis environment
r = redis.Redis(host='localhost', port=7622, db=0, decode_responses=True)
item_list = r.keys(pattern='*app_access##qa_press_test*')
# need to determine if there is a matching value, if not, it will report an error, so need to determine the processing
if len(item_list):
# Batch delete all cached application keys
r.delete(*r.keys(pattern='app_access*'))
logger.info("clear success...")
else:
logger.warn("with no data need to delete...")
PS: there is a detail to note here, that is, deleting directly without matching data will report an error, which needs to be handled
Note: conn.keys (‘test ‘) returns a list matching the corresponding pattern. Through the * sign, you can see that the parameters in the delete () method use variable parameters, that is, you can pass in a variable number of key values and delete them all.
Read More:
- Python: How to Delete Empty Files or Folders in the Directory
- Pytorch: How to Handle error warning conda.gateways.disk.delete:unlink_or_rename_to_trash(140)
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- [Solved] celery Startup Error: kombu.exceptions.VersionMismatch: Redis transport requires redis-py versions 3.2.0 or later. You have 2.10.6
- [Solved] TUM associate.py Scripte Error: AttributeError: ‘dict_keys‘ object has no attribute ‘remove‘
- Python: How to Processe “return multiple values”
- How to Fix keyerror in Python dictionary lookup
- Python: How to Solve mysqlclient Install Error in Mac
- An introduction to sys modules in Python and how packages are imported and used
- Python: How to Set Line breaks and tabs for Strings
- [CHM] Python: How to Extract CHM Data
- Python: How to Disable InsecureRequestWarning error
- Python: How to Solve error While importing windpy
- Python: How to Reshape the data in Pandas DataFrame
- How to Solve Python3.9 Install pycrypto Error
- How to Solve Python Xlwt ValueError: More than 4094 XFs (styles)
- Python: How to Auto Add Watermark to PDF
- Python: How to Obtaining Publick IP Quickly
- How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’
- Python: How to Use os.path.join()