Skip to content

Tunable CAP controls

tpjg edited this page May 27, 2013 · 7 revisions

Riak has "tunable CAP controls", see http://docs.basho.com/riak/latest/tutorials/fast-track/Tunable-CAP-Controls-in-Riak/ for more information.

The CAP control options must be supplied to an RObject when it gets created. Once created the options will automatically be used for all subsequent operations (like Reload, Store, Destroy). The controls can be supplied as one or more map[string]uint32 values, like in the example below:

obj := bucket.NewObject("new_key", map[string]uint32{"r": 1, "w": 1})

There are predefined values for R=1, PR=1, W=1, DW=1, PW=1:

obj := bucket.NewObject("new_key", riak.R1, riak.W1, riak.PW1)
// or retrieve an already existing object from Riak:
obj2, err := bucket.Get("existing_key", riak.R1, riak.W1, riak.PW1)

Also for Document Models (ORM) these options can be supplied when the model is retrieved or created, like in the example below:

type Device struct {
    DownloadEnabled  bool    `riak:"download_enabled"`
    Ip               string  `riak:"ip"`
    Description      string  `riak:"description"`
    riak.Model       `riak:"devices"`
}

...

var dev Device 
err = riak.NewModel("new_key", &dev, riak.W1, riak.PW1)
// or retrieve an already existing Document Model from Riak:
err = riak.LoadModel("existing_key", &dev, riak.W1, riak.PW1)

// create a new model in another (non-default) bucket:
err = riak.NewModelIn("other_devices", "new_key", &dev)
// load a model from another (non-default) bucket:
err = riak.LoadModelFrom("other_devices", "existing_key", &dev)
Clone this wiki locally