清理Redis常用手段
💡

清理Redis常用手段

shell 脚本

redis-cli -c -h -p -a scan xxx | args -L redis-cli -c -h -p del

python脚本清理一些hash 的 fields

#!/usr/bin/env python3 import redis # 导入redis 模块 r = redis.Redis(host='r-bp11w15hedzgmm33l5.redis.rds.aliyuncs.com', port=6379, password= 'lotusad4@HMI', decode_responses=True) hashVals = r.hkeys('InsFbs') delList = [] for key in hashVals: if str(key).startswith('dGVzdGFsaXl1c2'): r.hdel('InsFbs', delList)
遇到错误:/usr/bin/env: ‘python3\r’: No such file or directory [duplicate]
解决办法:
The problem are your line ending characters. Your file was created or edited on a Windows system and uses Windows/DOS-style line endings (CR+LF), whereas Linux systems like Ubuntu require Unix-style line endings (LF).
There is a simple tool that can convert the two different styles for you called dos2unix.
Install it by running
sudo apt install dos2unix
After that, you can convert files in either direction using one of the commands
dos2unix /PATH/TO/YOUR/WINDOWS_FILE unix2dos /PATH/TO/YOUR/LINUX_FILE
要注意的是开头要写明要执行的bash执行器位置。这里是python