I have a sorted set which has the following key name and values :
zrange bargraph:branch:1:category:2:product:4
1) \"76\"
2) \"55\"
3) \"10\"
4) \"84\"
<
As you've mentioned, KEYS is inefficient because the engine performs a linear scan for keys. Unfortunately, there is no wildcard solution such as you are looking for
Consider using a SET for your product keys per category:
SADD bargraph:branch:1:category:2 1 2 3 4
to fetch all set category members do:
SMEMBERS bargraph:branch:1:category:2
If you don't care about summing your scores, or have different items per a sorted set, you can do a union of your per product sorted sets like this:
ZUNIONSTORE bargraph:branch:1:category:2:product:all 4 bargraph:branch:1:category:2:product1 bargraph:branch:1:category:2:product2 bargraph:branch:1:category:2:product3 bargraph:branch:1:category:2:product4
and now you can zrange bargraph:branch:1:category:2:product:all
You pipeline the above operations for better performance