xargs: Warning: a NUL character occurred in the input.

  • A+
所属分类:BLOG Database Linux

今天遇到一个问题,批量删除redis里的keys报错。原因是java程序在做序列化的时候生成了一些特殊的key!

redis数据如下: xargs: Warning: a NUL character occurred in the input. 批量删除的脚本如下:

redis-cli -h 192.168.11.156 -p 6379 keys "*chnl-stock-mda-*" | xargs redis-cli -h 192.168.11.156 -p 6379 del

但是执行后报Warning且数据未删除:

xargs: Warning: a NUL character occurred in the input.  It cannot be passed through in the argument list.  Did you mean to use the --null option?

再次Google,发现一个解决办法: redis支持 lua脚本,调用lua脚本执行

local key=KEYS[1]
local list=redis.call("keys", key);
for i,v in ipairs(list) do
    redis.call("del", v);
end

保存为de.lua文件 执行命令:

redis-cli -h 192.168.11.156 -p 6379 --eval ./de.lua "*chnl-stock-mda-*" 

再次登录redis查看,完全删除!

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: