import redis # Redis连接信息 redis_host = 'hostname' redis_port = 6379 redis_password = 'passwd' redis_db = 5 # 选择数据库5 # 连接到Redis服务器 redis_client = redis.StrictRedis( host=redis_host, port=redis_port, password=redis_password, db=redis_db, decode_responses=True ) # 选择数据库 redis_client.select(redis_db) # 获取以'whiteKey:'开头的所有键 keys_to_delete = redis_client.keys('whiteKey:*') # 批量删除键 if keys_to_delete: redis_client.delete(*keys_to_delete) print(f"成功删除 {len(keys_to_delete)} 个以'whiteKey:'开头的键。") else: print("没有以'whiteKey:'开头的键需要删除。")
标签:whiteKey,keys,db,redis,client,68,delete From: https://www.cnblogs.com/leiuk/p/17879514.html