As an example, we're dealing with product data. One of the fields in
my testing is product category. If we're setting a key like
"product:123:category" with a value like "Electronics", what would be
the fastest and most efficient way to find all of the keys with a
matching value -- if I wanted to get all of the products in the
"Electronics" category.
Obviously I could place those into a set based on the category, so
perhaps that's not the best example, but if I tried to create a set
for every field and every value, it will quickly multiply into numbers
that are far too large. Alternately, if a field is product title:
key="product:123:title", value="LCD Television"
key="product:456:title", value="Plasma Television"
And I want to get the keys for all products where title contains
"Television". I can of course get all of the title keys by
constructing an MGET, but that could be a million keys. If I then need
to get the values and compare each against a pattern like
"*Television*", it doesn't seem so efficient. If I could at least get
all of the keys that match a pattern, it would help a bit -- are there
plans for this?
Any suggestions for better ways to handle this would be great.
Thanks.
-- Mason
Yes, I guess I wasn't clear enough -- I meant where the *values* match
a pattern. For example, like a traditional RDBMS query of "select id
where category='electronics'", I want all of the keys where the values
match. I realize this isn't the ideal use of redis; it's a sort of
sideways requirement we have.
>> As an example, we're dealing with product data. One of the fields in
>> my testing is product category. If we're setting a key like
>> "product:123:category" with a value like "Electronics", what would be
>> the fastest and most efficient way to find all of the keys with a
>> matching value -- if I wanted to get all of the products in the
>> "Electronics" category.
>
> You have to do this in a simpler way.
> Every time you add a product in the electronic category you "tag" it into a Set:
>
> SADD category:Electronics <your-product-id>
>
> To get all the IDs of the products under Electronics:
>
> SELEMENTS category:Electronics
>
> To get the name and price of all this procuts in Electronics, sorted by prince:
>
> SORT category:Electronics BY product:*:price GET product:*:name GET
> product:*:price
So that implies that the above does a "query" of the elements in the
"category:Electronics" set and returns just the two name and price
elements?
Doing this might work, but it is possible for a customer to have many
categories, and there are other similar field types that we need to
treat this way (such as Manufacturer). If this results in several
thousand tags being applied to a few million elements, would it scale?
>> key="product:123:title", value="LCD Television"
>> key="product:456:title", value="Plasma Television"
>>
>> And I want to get the keys for all products where title contains
>> "Television". I can of course get all of the title keys by
>
> Ok if you want to match *by value* Redis is not a good idea at all,
> otherwise you need to have Sets in order to perform a FULLTEXT
> indexing of the fields you want to search against.
Yes, I thought so. I believe that perhaps we may have only a few
fields where we must have a full-text search, and it may make sense to
separately index them outside redis, map to ids, and then use redis to
get the rest of the information. We'll see about that.
> Hope this helps!
Yes, thank you. I have some more things to try now!
-- Mason