Skip to content

Instantly share code, notes, and snippets.

@ctoestreich
Created May 6, 2016 14:36
Show Gist options
  • Save ctoestreich/827d21fcdefc03844489e9cbced4dbbd to your computer and use it in GitHub Desktop.
Save ctoestreich/827d21fcdefc03844489e9cbced4dbbd to your computer and use it in GitHub Desktop.
// deletes all keys matching a pattern (see redis "keys" documentation for more)
// OK for low traffic methods, but expensive compared to other redis commands
// perf test before relying on this rather than storing your own set of keys to
// delete
void deleteKeysWithPattern(keyPattern) {
if (log.infoEnabled) log.info("Cleaning all redis keys with pattern [${keyPattern}]")
withRedis { Jedis redis ->
String[] keys = redis.keys(keyPattern)
if(keys) redis.del(keys)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment