Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis cli delete multiple keys

I have installed Redis in centos and I have multiple keys of redis like this,

Product:<id>:<url>

How can I delete all Product:*:* with CLI ?

Redis version : 3.2.4 [ Latest I guess ]

Thanks!

like image 446
John FG Avatar asked Nov 18 '16 13:11

John FG


People also ask

How do I delete multiple keys in Redis?

Redis does not offer a way to bulk delete keys. You can however use redis-cli and a little bit of command line magic to bulk delete keys without blocking redis. This command will delete all keys matching users:* If you are in redis 4.0 or above, you can use the unlink command instead to delete keys in the background.

How do I flush all Redis?

To clear data of a DCS Redis 4.0 or 5.0 instance, you can run the FLUSHDB or FLUSHALL command in redis-cli, use the data clearing function on the DCS console, or run the FLUSHDB command on Web CLI. To clear data of a Redis Cluster instance, run the FLUSHDB or FLUSHALL command on every shard of the instance.

Can Redis have multiple keys?

Redis quickly stretched this concept with data types, where a single key could refer to multiple (even millions of) pieces of data. As modules came to the ecosystem, the idea of a key was stretched even further because a single piece of data could now span multiple keys (for a RediSearch index, for example).


1 Answers

Using the redis-cli tool, you can do the following:

redis-cli --scan --pattern 'Product:*:*' | xargs redis-cli DEL
like image 93
Itamar Haber Avatar answered Sep 19 '22 19:09

Itamar Haber