How to structure data in Riak?

后端 未结 2 995
终归单人心
终归单人心 2020-12-15 08:48

I\'m trying to figure out how to model data in Riak. Let\'s say you are building something like a CMS with two features, news and products. You need to be able to store this

2条回答
  •  旧时难觅i
    2020-12-15 09:41

    I'd create 2 buckets: news and products. Then I'd prefix keys in each bucket with client names. I'd probably also include dates in news keys for easy date ranging.

    news/acme_2011-02-23_01
    news/acme_2011-02-23_02
    news/bigcorp_2011-02-21_01
    

    And optionally prefix product names with category names

    products/acme_blacksmithing_anvil
    products/bigcorp_databases_oracle
    

    Then in your map/reduce you could use key filtering:

    // BigCorp News items
    {
      "inputs":{
         "bucket":"news",
         "key_filters":[["starts_with", "bigcorp"]]
      }
      // ... rest of mapreduce job
    }
    
    // Acme Blacksmithing items
    {
      "inputs":{
         "bucket":"products",
         "key_filters":[["starts_with", "acme_blacksmithing"]]
      }
      // ... rest of mapreduce job
    }
    
    // News for all clients from Feb 12th to 19th
    {
      "inputs":{
         "bucket":"news",
         "key_filters":[["tokenize", "_", 2],
                        ["between", "2011-02-12", "2011-02-19"]]
      }
      // ... rest of mapreduce job
    }
    

提交回复
热议问题