coolexp / redis

Automatically exported from code.google.com/p/redis
0 stars 0 forks source link

MDELETE possible? #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

Currently we use a Java OSCache w/ the notion of "groups" which allow for
flexible cache management in certain situations.  One thing we noticed w/
Redis is that you can not delete multiple keys in a single shot, is this
something that would be possible to accomplish?

Thanks.

- Jon

Original issue reported on code.google.com by jonb...@gmail.com on 4 May 2009 at 6:28

GoogleCodeExporter commented 8 years ago
Hello Jon,

added to the TODO list. This is a useful primitive that's worth adding.

Original comment by anti...@gmail.com on 4 May 2009 at 9:44

GoogleCodeExporter commented 8 years ago
implemented in Redis-git in the form of vararg DEL.

Original comment by anti...@gmail.com on 9 May 2009 at 7:05

GoogleCodeExporter commented 8 years ago
Hi,

I tried this out but noticed you could not wildcard keys:

SET group:one:1 3
foo
SET group:one:2 3
bar
DEL group:one:*

This would be equivalent to saying KEY group:one:* and then issuing a multiple 
DEL in
a loop but that was the initial issue we were hoping this would solve (to avoid 
2
calls), MDEL (multiple delete) ... we are basically trying to "group" keys and
simulate a current setup w/ Redis ...

Original comment by jonb...@gmail.com on 9 May 2009 at 8:30

GoogleCodeExporter commented 8 years ago
Hello!

this is not going to be a good idea. KEYS <pattern> is an O(N) operation. With 
your
design you are going to severely reduce the good things a KV store gives to 
you, that
is: scalability and easy partitioning.

We have a single operating doing pattern matching that is KEYS, since sometimes 
it's
not a matter of speed, but, for instance, of reconstructing data and keys after 
a DB
schema switch. But it's not suggested to use pattern matching for actual work.

What you want to do is trivially accomplished adding the sub-keys you have for 
every
group into a set with "SADD group:one:fields 1" and so on. Then when you need to
remove the whole group just perform a SMEMBERS to get all the members of the set
followed by a multi-argument delete. This appears to be slower since takes two 
steps
and two commands, but actually this is an O(1) operation so this is going to 
scale
very well.

Regards,
Salvatore

Original comment by anti...@gmail.com on 9 May 2009 at 9:21