I'm trying to MSET all values in my Redis. I was thinking about piping the SCAN or KEYS * command to MSET but I'm not sure if that's possible.
Related
I have want to delete field in redis hash by pattern (more specifically prefix). I tried following and it doesn't work.
hdel <some_key> <prefix>*
How to achieve this ?
By default, Redis does not provide a way to bulk remove keys that match a specific pattern. However, we can leverage the power of the command line to perform this action.
We will use the xargs to build and run commands back to Redis for this one. An example is as shown below:
redis-cli --scan --pattern "prefix*" | xargs redis-cli del
I have hundreds of thousands of keys that start with html: that I need to clean up quickly. Instead of writing a python script to do this, I was hoping for a simple command via redis-cli to do this. I was surprised to not find one. I am assuming I can do something with xargs from the linux terminal but I need to also pass in the auth password to redis.
After some munging and experimentation, I found this combination to work perfectly to remove all the keys I needed that match the beginning from left to right in the key name itself. It was very fast to run, which is no surprise since redis is in memory.
redis-cli -a <mypassword> --raw keys "html:*" | xargs redis-cli -a <mypassword> del
I am saving no.of(1000) records in Redis DB , while checking in redis CLI dbsize as its exactly double actually. Can any one having any idea why its saved double? Thanks!
I have installed redis on my ubuntu server. I am traying to learn commands via redis-cli. I am seetnigs commands:
127.0.0.1:6379> SET book "read"
127.0.0.1:6379> GET book
127.0.0.1:6379> DEL book
And I can list multiple keys like this:
127.0.0.1:6379> KEYS "urn:products:*"
These commands work fine but I want to delete multiple records with pattern.
127.0.0.1:6379> DEL "urn:products:*"
127.0.0.1:6379> DEL KEYS "urn:products:*"
These commands not deleting records
The DEL command doesn't accept a wildcard. In your first example you're trying to delete a key named urn:products:* and in the second example you're trying to delete 2 keys named KEYS and urn:products:*.
If you want to delete a bunch of keys by a pattern you'll have to first run KEYS (or you should really be using SCAN) and then DELETE them in batches.
As of the upcoming v3.4, you'll be able to use the PDEL command from the rxkeys module. This variant the accepts POSIX Extended Regular Expressions.
I am new to jedis. I am not able to distinguish del() and flushAll(). Does del() deletes the keys from cache or from database. Kindly provide some details.
Please note, I did try to search for an answer on the web, but could't fine my answer.
Thank you.
DEL: Deletes a single key
redis 127.0.0.1:6379[1]> SET foo bar
OK
redis 127.0.0.1:6379[1]> SET XXX YYY
OK
redis 127.0.0.1:6379[1]> keys *
1) "XXX"
2) "foo"
redis 127.0.0.1:6379[1]> DEL foo
(integer) 1
redis 127.0.0.1:6379[1]> keys *
1) "XXX"
FLUSHALL Redis has 12 Database by default you can choose a database by SELECT command
redis 127.0.0.1:6379[1]> SELECT 11
IMPORTANT TO REMEMBER IF YOU USE FLUSHALL COMMAND IT WILL DELETE DATA FROM ALL 12 DATABASES
FLUSHDB: Deletes all keys from CURRENT database. May be you would like to use it in 90% of cases instead of FLUSHALL