title: Grouping Data in a Key/Value Database Like Redis
body: <p>I'm trying to model data similar to amazon.com categories (e.g., books, movies, electronics, etc.) in a Redis database. Order matters to me when they're rendered on an HTML page so that the user is presented with a consistent user interface. As such, I stored the categories in a Sorted Set:</p>
  
  <pre><code>ZADD categories 0 "Books"
  ZADD categories 1 "Movies"
  ZADD categories 2 "Electronics"
  </code></pre>
  
  <p>I then created another Sorted Set for each of the sub-categories.</p>
  
  <pre><code>ZADD categories:books 0 "Fiction"
  ZADD categories:books 1 "Non-Fiction"
  ZADD categories:movies 0 "Horror"
  [...]
  </code></pre>
  
  <p>From here, I figured I could store products in a Hash.</p>
  
  <pre><code>HMSET product:1000 category 0 subcategory 0 title "Redis Cookbook"
  HMSET product:1001 category 1 subcategory 0 title "Nightmare on Elm Street"
  [...]
  </code></pre>
  
  <p>I'm very new to both Redis and Key/Value database stores, so I'm anything but confident in my approach. Is this model going to work for me long-term? Is there a better/alternative approach I should be aware of? One concern I have is keeping the names "synchronized". For example, if I change the top-level category from "Books" to "Literature" (terrible example, I know) all of the keys for the sub-categories that "reference" books <em>should</em> also be updated.</p>