Redis 正则批量删除 key

2023-08-23 18:46:32 浏览数 (2)

代码语言:javascript复制
EVAL "return redis.call('del', 'defaultKey', unpack(redis.call('keys', ARGV[1])))" 0 prefix:*

循环删除:

代码语言:javascript复制
EVAL "local keys = redis.call('keys', ARGV[1]) n for i=1,#keys,5000 do n redis.call('del', unpack(keys, i, math.min(i 4999, #keys))) n end n return keys" 0 prefix:*

References

  • How to atomically delete keys matching a pattern using Redis | stackoverflow

– EOF –

  • # redis

0 人点赞