Redis登陆服务器和批量删除指定的key
ps -ef |grep redis
cd /opt/app/redis/bin
./redis-cli -h 192.168.0.67 -p 7001 -a 'hub2c!Redis'
./redis-cli -h 192.168.0.68 -p 7001 -a 'hub2c!Redis'
./redis-cli -h 192.168.0.71 -p 7001 -a 'hub2c!Redis'
使用ttl查看超时时间,如果是-1表示没有超时时间。
192.168.0.71:7001> ttl "v1HKGLAXHXLOWHK52E2018-12-14T12:00:00"
删除所有Key,可以使用Redis的flushdb和flushall命令
按照正则表达式批量删除
redis-cli keys "PRO*" |xargs redis-cli del
如果需要用户名密码,则整个命令例子如下:
./redis-cli -h 192.168.0.71 -p 7001 -a 'hub2c!Redis' keys "v1*"|xargs ./redis-cli -h 192.168.0.71 -p 7001 -a 'hub2c!Redis' del
上面的71是slave,没有删除的权限。
./redis-cli -h 192.168.0.68 -p 7001 -a 'hub2c!Redis' keys "v1*"|xargs ./redis-cli -h 192.168.0.68 -p 7001 -a 'hub2c!Redis' del
注意,slave是没有删除权限的,要去master服务器删除key
[jboss5@OpenJawRedis bin]$ ./redis-cli -h 192.168.0.71 -p 7001 -a 'hub2c!Redis'
192.168.0.71:7001> del "v1HKGLAXHXLOWHK52E2018-12-14T12:00:00"
(error) READONLY You can't write against a read only slave.
192.168.0.71:7001> exit
[jboss5@OpenJawRedis bin]$ ./redis-cli -h 192.168.0.68 -p 7001 -a 'hub2c!Redis'
192.168.0.68:7001> del "v1HKGLAXHXLOWHK52E2018-12-14T12:00:00"
(integer) 1
192.168.0.68:7001>