title: Recessively query Redis based on data type
body: <p>I am representing JSON objects in Redis by flattening the JSON path keys like so:</p>
  
  <h2>JSON object</h2>
  
  <pre class="lang-json prettyprint-override"><code>{
      "users": [
          {
              "name": "John Smith",
              "address": {
                  "street": "12 Rainbow Avenue",
                  "country": "Fuzzyland"
              }
          }, {
              "name": "Billy Bob",
              "address": {
                  "street": "8 Rocky Lane",
                  "country": "Fraggleville"
              }
          }
      ]
  }
  </code></pre>
  
  <h2>Redis entries</h2>
  
  <pre class="lang-javascript prettyprint-override"><code>users // SET [0, 1]
  users:0 // SET [name, address]
  users:0:name // STRING "John Smith"
  users:0:address // SET [street, country]
  users:0:address:street // STRING "12 Rainbow Avenue"
  users:0:address:country // STRING "Fuzzyland"
  users:1 // SET [name, address]
  users:1:name // STRING "Billy Bob"
  users:1:address // SET [street, country]
  users:1:address:street // STRING "8 Rocky Lane"
  users:1:address:country // STRING "Fraggleville"
  </code></pre>
  
  <p>As you can see, for properties that are arrays or object literals I am using a Redis SET to store the available keys.</p>
  
  <p>It is easy enough for me to convert the JSON object to this structure using Node. However I am not experienced enough with Redis to write recursive queries that stitch together a complex result.</p>
  
  <p>For example, say I want to get all the keys and values for <code>users:1</code>. How do I write a query that looks at the value of <code>users:1</code> sees that it is a SET so uses the values from that as another set of query keys?</p>