Redis Cluster: How to BULK DELETE ?

1,924 views
Skip to first unread message

newgu...@gmail.com

unread,
Mar 24, 2016, 3:10:13 AM3/24/16
to Redis DB
Hi All,

I've created cluster environment with 6 Redis(v3.0) instances (3 Master & 3 Replicas).

Questions:
1. What is the recommended to perform BULK DELETE of all keys matching given pattern?
2. I learnt KEYS command is not recommended in production environment? Why is it so ?
3. I learnt SCAN command is reliable? Why is it so?

Regards,
NewGuy :)

AlexanderB

unread,
Mar 24, 2016, 2:08:37 PM3/24/16
to Redis DB
Redis overall isn't really good at wildcard / patterns based commands. It's totally possible to do so, but do to the tradeoffs that Redis makes and fundamental algorithmic complexity issues, it's never going to be as fast as using Redis for what it's really good at. 

Keys vs Scan:

The biggest difference between the two is that KEYS loops over and checks every single key without pause, while Scan checks a few keys at a time. 
When you have a lot of keys checking all of them can take a relatively long time. Redis makes a lot of design choices assuming, that you're running a large number of short to run commands, rather than a few very long ones. 

Redis only runs a single command at a time, so long commands, can cause others to queue up behind it.  

By using SCAN, your wildcard delete will still take a long time, but it will allow other commands to the Redis server to run in between scan calls, without there ever being a big long command queued in front of it. 

Another option would be to keep track of all the keys you might want to delete when you're adding them, rather than by pattern checking later. This would only work if it's predictable which keys you'd later want to delete. You'd need to build a custom index structure, based on the needs of your business case, but if that potentially interests you, I'd suggest giving Itamar Redis index slides a look as the first step down that Rabit hole. http://www.slideshare.net/itamarhaber/20140922-redis-tlv-redis-indices

Itamar Haber

unread,
Mar 24, 2016, 2:49:18 PM3/24/16
to Redis DB
:) ...and even before that mad-hatter's preso, read the doc page about indexing: http://redis.io/topics/indexes

The important thing to know about "BULK" operations is whether atomicity is required. Because atomic bulk operations can take a long time to complete, these are sort of against the Redis spirit (Redis likes predictable, preferably constant, complexities for its operations) and the cluster's design isn't really suitable for that (no cross-slot transactions).

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Chief Developer Advocate
Redis Watch Newsletter | &&(curat||edit||janit||)
Redis Labs | ~ of Redis

Mobile: +972 (54) 567 9692
Email: ita...@redislabs.com
Twitter: @itamarhaber
Skype: itamar.haber

Blog  |  Twitter  |  LinkedIn

 #RedisConf

Reply all
Reply to author
Forward
0 new messages