顺子の杂货铺
生命不息,折腾不止,且行且珍惜~

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

DMIT VPS

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

redis数据如下:
file
批量删除的脚本如下:

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查看,完全删除!

赞(0)
未经允许不得转载:順子の杂货铺 » xargs: Warning: a NUL character occurred in the input.
搬瓦工VPS

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

分享创造快乐

联系我们联系我们