Skip to content

Delete Redis keys by pattern in a non-blocking manner

License

Notifications You must be signed in to change notification settings

alexdzyoba/redis-del-keys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-del-keys

Release Software License Travis

Delete keys in Redis by a pattern. Deletion is performed by doing SCAN and then invoking DEL in a pipeline. This allows you to delete the keys in a non-blocking manner.

Usage

Simple invocation requires pattern argument:

$ redis-del-keys 
pattern argument is required

redis-iter-del iterates over redis keys with SCAN matched by pattern and then
DEL the keys in pipelined commands

Usage of redis-del-keys:
  -a, --addrs strings    Redis addrs, comma separated for cluster (default [:6379])
  -b, --batch int        Batch size for pipelined commands (default 10)
  -c, --count int        Count for SCAN command (default 10)
  -d, --dryrun           Dry run
  -p, --pattern string   Pattern to delete

This prevents you from accidentally deleting all of the keys.

Real example:

$ redis-del-keys -p 'a*'
iterated over 10 keys

It prints how many keys it has iterated. Running this command again will iterate over 0 keys because they were deleted:

$ redis-del-keys -p 'a*'
iterated over 0 keys

The command supports dry run mode via -d or --dryrun option. It is safe and allows you to estimate how many keys will be deleted:

$ redis-del-keys -d -p '*'
iterated over 240 keys