Redis/Jedis - Delete by pattern?

iCodeLikeImDrunk picture iCodeLikeImDrunk · Jan 23, 2014 · Viewed 31.8k times · Source

Normally, I get the key set then use a look to delete each key/value pair.

Is it possible to just delete all keys via pattern?

ie:

Del sample_pattern:*

Answer

iCodeLikeImDrunk picture iCodeLikeImDrunk · Jan 27, 2014

It seems, for Jedis, to "delete by pattern" is basically getting all the keys of a specific pattern then loop through it.

ie

Set<String> keys = jedis.keys(pattern);
for (String key : keys) {
    jedis.del(key);
}