Redis delete element in multiple sets

I have an element XYZ in multiples sets and i nee to delete is from all the sets.

I could do:

SADD SET1 1 2 3
SADD SET2 3 4 5

And:

SREM SET1 3
SREM SET2 3

But I don't know the name of the sets in advance, is there a simple way to do something like

FOREACH SET* do SREM 3

Upvotes: 3

Views: 217

Answers (1)

Itamar Haber
Itamar Haber

Reputation: 49942

Keep another set of Sets that maps elements to the Sets that they're in. In your example, that would mean:

SADD member:1 SET1
SADD member:2 SET1
SADD member:3 SET1 SET2
SADD member:4 SET2
SADD member:5 SET2

Once everything is set, all you need to do is get the members in the member:3 Set and continue with the "FOREACH".

Upvotes: 2

Related Questions