I want to remove keys that match "user*".
How do I do that in redis command line?
For desktop keyboards, take a butter knife or a screwdriver and try to pry up one corner of the keys. You don't need to use a lot of force; you should feel a pop and the key will come right off. For laptop keyboards, your fingernail should be enough to pull the plastic up.
Simply take a paper clip, unfold it into a straight line, and then make an L shape. Then all you need to do is slide it under a keycap and then lift. The keycap should pop right off. It's not perfect and may need to be reformed many times before all your keys are pulled, but it's super simple.
What you need to remove laptop keys. While you can purchase keyboard key removal tools, you can also easily remove laptop keys using a flat head screwdriver. When cleaning your laptop keys, all you will need is some compressed air, rubbing alcohol, and cotton swabs.
Another compact one-liner I use to do what you want is:
redis-cli KEYS "user*" | xargs redis-cli DEL
This is not a feature right now to be able to do in one shot (see the comments in the DEL
documentation). Unfortunately, you are only left with using KEYS
, looping through the results, and then using DEL
to remove each one.
How about using bash a bit to help?
for key in `echo 'KEYS user*' | redis-cli | awk '{print $1}'`
do echo DEL $key
done | redis-cli
To step through it:
echo 'KEYS user*' | redis-cli | awk '{print $1}'
-- get all the keys and strip out the extra text you don't want with awk.echo DEL $key
-- for each one, create an echo statement to remove it.| redis-cli
-- take the DEL statements and pass them back into the cli.Not suggesting this is the best approach (you might have some issues if some of your usernames have spaces in them, but hopefully you get the point).
Now there is a command to remove a key,i.e., DEL key [keys]
DEL key...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With