Skip to content

Instantly share code, notes, and snippets.

@nikopol
Created August 2, 2021 14:56
Show Gist options
  • Save nikopol/cf0ecfbcd25cfcd563dd9ee8ee55cb68 to your computer and use it in GitHub Desktop.
Save nikopol/cf0ecfbcd25cfcd563dd9ee8ee55cb68 to your computer and use it in GitHub Desktop.
fish fn to delete multiple keys in a redis at once
function redis-del
set cmd (status current-command)
set _flag_host 'localhost'
set _flag_port '6379'
set _flag_db '0'
argparse 'help' 'h/host=' 'p/port=' 'n/db=' -- $argv
if test -n "$_flag_help" -o -z "$argv"
test -z "$argv"; and echo -e "missing key!\n"
echo "delete multiple keys in a redis at once"
echo
echo "syntax: $cmd [--options] key"
echo
echo "+---options---+---alternative---+--default----+"
echo "| -h=hostname | --host hostname | localhost |"
echo "| -p=port | --port port | 6379 |"
echo "| -n=database | --db database | 0 |"
echo "+-------------+-----------------+-------------+"
echo
echo "eg: redis-del -h cl03-redis-v301 --db=1 'geocoder-*'"
else if command -v redis-cli >/dev/null
echo "searching $argv on $_flag_host:$_flag_port/$_flag_db"
for k in (redis-cli --raw -h $_flag_host -p $_flag_port -n $_flag_db KEYS $argv)
test -n "$k"; and echo 'del' $k (redis-cli --raw -h $_flag_host -p $_flag_port -n $_flag_db DEL $k)
end
else
echo "redis-cli is required"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment