Exclude pattern in Keys command?

1,350 views
Skip to first unread message

Fernando

unread,
Nov 28, 2012, 4:14:24 PM11/28/12
to redi...@googlegroups.com
I have several keys with the following structure.:

people:123
people:123:addresses
people:123:telephones
people:123:relatives
people:123:etc

Where 123 is variable length identifier.
I need to find all the keys that follows the first pattern, but not the others.

Is there a way to accomplish what I need to do without having to create and mantain a key with a set for people?
I need id to do a batch process so it is ok if it not the best solution.


Thanks

Felix Gallo

unread,
Nov 28, 2012, 4:31:13 PM11/28/12
to redi...@googlegroups.com
The best and most correct way to do it is to create a set for people.

If for some reason you absolutely cannot do that, then:

a) if your identifier is contiguously monotonically increasing, loop through "people:N" where N is 1 to infinity until you get a nil key response.

b) if you know the names of all of your subkeys (addresses, telephones, etc.), then do a KEYS people:*, then a KEYS people:*:addresses, then a KEYS people:*:telephones, and so on, saving each to a an array.  Subtract the subkey arrays from the KEYS people:* array.  Voila.

F.


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/olrKEVHblOEJ.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Reply all
Reply to author
Forward
0 new messages