Documentation ¶
Overview ¶
Package riak is a riak-client, inspired by the Ruby riak-client gem and the riakpbc go package from mrb. It implements a connection to Riak using protobuf.
Index ¶
- Variables
- func Close()
- func ConnectClient(addr string) (err error)
- func ConnectClientPool(addr string, count int) (err error)
- func DeleteFrom(bucketname string, key string, options ...map[string]uint32) (err error)
- func ExistsIn(bucketname string, key string, options ...map[string]uint32) (exists bool, err error)
- func Id() (id string, err error)
- func IsWarning(err error) bool
- func LoadModel(key string, dest Resolver, options ...map[string]uint32) (err error)
- func LoadModelFrom(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
- func NewModel(key string, dest Resolver, options ...map[string]uint32) (err error)
- func NewModelIn(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
- func Ping() (err error)
- func RunMapReduce(query string) (resp [][]byte, err error)
- func ServerVersion() (node string, version string, err error)
- func SetId(id string) (err error)
- type Bucket
- func (b *Bucket) AllowMult() bool
- func (b *Bucket) Delete(key string, options ...map[string]uint32) (err error)
- func (b *Bucket) Exists(key string, options ...map[string]uint32) (exists bool, err error)
- func (b *Bucket) Get(key string, options ...map[string]uint32) (obj *RObject, err error)
- func (b *Bucket) IndexQuery(index string, key string) (keys []string, err error)
- func (b *Bucket) IndexQueryRange(index string, min string, max string) (keys []string, err error)
- func (b *Bucket) ListKeys() (response [][]byte, err error)
- func (b *Bucket) NVal() uint32
- func (b *Bucket) Name() string
- func (b *Bucket) New(key string, options ...map[string]uint32) *RObject
- func (b *Bucket) NewObject(key string, options ...map[string]uint32) *RObject
- func (b *Bucket) SetAllowMult(allowMult bool) (err error)
- func (b *Bucket) SetNVal(nval uint32) (err error)
- type Client
- func (c *Client) Bucket(name string) (*Bucket, error)
- func (c *Client) Close()
- func (c *Client) Connect() (err error)
- func (c *Client) DeleteFrom(bucketname string, key string, options ...map[string]uint32) (err error)
- func (c *Client) ExistsIn(bucketname string, key string, options ...map[string]uint32) (exists bool, err error)
- func (c *Client) GetFrom(bucketname string, key string, options ...map[string]uint32) (obj *RObject, err error)
- func (c *Client) Id() (id string, err error)
- func (c *Client) Key(dest interface{}) (key string, err error)
- func (c *Client) Load(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
- func (c *Client) LoadModel(key string, dest Resolver, options ...map[string]uint32) (err error)
- func (c *Client) LoadModelFrom(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
- func (c *Client) MapReduce() *MapReduce
- func (c *Client) New(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
- func (c *Client) NewBucket(name string) (*Bucket, error)
- func (c *Client) NewModel(key string, dest Resolver, options ...map[string]uint32) (err error)
- func (c *Client) NewModelIn(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
- func (c *Client) NewObjectIn(bucketname string, key string, options ...map[string]uint32) (*RObject, error)
- func (c *Client) Ping() (err error)
- func (c *Client) RunMapReduce(query string) (resp [][]byte, err error)
- func (c *Client) Save(dest Resolver) (err error)
- func (c *Client) SaveAs(newKey string, dest Resolver) (err error)
- func (c *Client) ServerVersion() (node string, version string, err error)
- func (c *Client) SetId(id string) (err error)
- func (c *Client) SetKey(newKey string, dest interface{}) (err error)
- type Link
- type Many
- type MapReduce
- func (mr *MapReduce) Add(bucket string, key string) (err error)
- func (mr *MapReduce) AddBucket(bucket string) (err error)
- func (mr *MapReduce) AddBucketRange(bucket string, start string, end string) (err error)
- func (mr *MapReduce) AddIndex(bucket string, index string, key string) (err error)
- func (mr *MapReduce) AddIndexRange(bucket string, index string, start string, end string) (err error)
- func (mr *MapReduce) LinkBucket(name string, keep bool)
- func (mr *MapReduce) Map(fun string, keep bool)
- func (mr *MapReduce) MapErlang(module string, fun string, keep bool)
- func (mr *MapReduce) MapObjectValue(keep bool)
- func (mr *MapReduce) Query() (query []byte, err error)
- func (mr *MapReduce) Reduce(fun string, keep bool)
- func (mr *MapReduce) Run() (resp [][]byte, err error)
- type Model
- func (m *Model) Delete() (err error)
- func (m *Model) GetSiblings(dest interface{}) (err error)
- func (m *Model) Indexes() map[string]string
- func (m Model) Key() (key string)
- func (m *Model) Reload() (err error)
- func (*Model) Resolve(count int) (err error)
- func (m *Model) Save() (err error)
- func (m *Model) SaveAs(newKey string) (err error)
- func (m Model) SetKey(newKey string) (err error)
- func (m *Model) Siblings(dest Resolver) (result interface{}, err error)
- func (m *Model) Vclock() (vclock []byte)
- type One
- type RObject
- type Resolver
- type Sibling
Constants ¶
This section is empty.
Variables ¶
var ( R1 = map[string]uint32{"r": 1} PR1 = map[string]uint32{"pr": 1} W1 = map[string]uint32{"w": 1} DW1 = map[string]uint32{"dw": 1} PW1 = map[string]uint32{"pw": 1} )
Options for storing and retrieving data, only a few are defined, different values can be supplied by creating a map in the application, for example:
bucket.Get("key", map[string]int{"r":2})
var ( BadNumberOfConnections = errors.New("Connection count <= 0") BadResponseLength = errors.New("Response length too short") NoBucketName = errors.New("No bucket name") BadMapReduceInputs = errors.New("MapReduce inputs should be either a (single) index or bucket,key pairs - not both at") )
Error definitions
var ( ResolveNotImplemented = errors.New("Resolve not implemented") DestinationError = errors.New("Destination is not a pointer (to a struct)") DestinationIsNotModel = errors.New("Destination has no riak.Model field") DestinationIsNotSlice = errors.New("Must supply a slice to GetSiblings") DestinationLengthError = errors.New("Length of slice does not match number of siblings") DestinationNotInitialized = errors.New("Destination struct is not initialized (correctly) using riak.New or riak.Load") ModelDoesNotMatch = errors.New("Warning: struct name does not match _type in Riak") ModelNotNew = errors.New("Destination struct already has an instantiated riak.Model (this struct is probably not new)") NoSiblingData = errors.New("No non-empty sibling data") )
Error definitions
var (
NoDefaultClientConnection = errors.New("No (default) client connection")
)
var (
NotFound = errors.New("Object not found")
)
Error definitions
Functions ¶
func ConnectClient ¶
Create the default client with a single connection to Riak.
func ConnectClientPool ¶
Create the default client, using a pool of connections. This is the recommended method to connect to Riak in an application. A single client instance can be used by multiple threads/goroutines and will not block operations if there are enough connections in the pool. NOTE: If an application needs connections to different Riak clusters it can use riak.NewClientPool or riak.NewClient.
func DeleteFrom ¶
Delete directly from a bucket, without creating a bucket object first
func ExistsIn ¶
Test if an object exists in a bucket directly, without creating a bucket object first
func IsWarning ¶
Return is an error is really a warning, e.g. a common json error, or ModelDoesNotMatch.
func LoadModel ¶
Load data into the model using the default bucket (from the Model's struct definition)
func LoadModelFrom ¶
func LoadModelFrom(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
The LoadModelFrom function retrieves the data from Riak using the default client and stores it in the struct that is passed as destination.
func NewModel ¶
Instantiate a new model (using the default client), setting the necessary fields, like the client. If key is not empty that key will be used, otherwise Riak will choose a key.
func NewModelIn ¶
func NewModelIn(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
Create a new Document Model (using the default client), passing in the bucketname and key.
func RunMapReduce ¶
Run a MapReduce query directly
func ServerVersion ¶
Get the server version for the default client
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Implements access to a bucket and its properties
func (*Bucket) IndexQuery ¶
Return a list of keys using the index for a single key
func (*Bucket) IndexQueryRange ¶
Return a list of keys using the index range query
func (*Bucket) SetAllowMult ¶
Set the allowMult property of a bucket
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
riak.Client the client interface
func NewClientPool ¶
Returns a new Client with multiple connections to Riak
func NewPool ¶
Returns a new Client with multiple connections to Riak. DEPRECATED, use NewClientPool instead
func (*Client) DeleteFrom ¶
func (c *Client) DeleteFrom(bucketname string, key string, options ...map[string]uint32) (err error)
Delete directly from a bucket, without creating a bucket object first
func (*Client) ExistsIn ¶
func (c *Client) ExistsIn(bucketname string, key string, options ...map[string]uint32) (exists bool, err error)
Test if an object exists in a bucket directly, without creating a bucket object first
func (*Client) GetFrom ¶
func (c *Client) GetFrom(bucketname string, key string, options ...map[string]uint32) (obj *RObject, err error)
Get directly from a bucket, without creating a bucket first
func (*Client) Load ¶
func (c *Client) Load(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
Load data into model. DEPRECATED, use LoadModelFrom instead.
func (*Client) LoadModel ¶
Load data into the model using the default bucket (from the Model's struct definition)
func (*Client) LoadModelFrom ¶
func (c *Client) LoadModelFrom(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
The LoadModelFrom function retrieves the data from Riak and stores it in the struct that is passed as destination. It stores some necessary information in the riak.Model field so it can be used later in other (Save) operations.
If the bucketname is empty ("") it'll be the default bucket, based on the riak.Model tag.
Using the "Device" struct as an example:
dev := &Device{} err := client.Load("devices", "12345", dev)
func (*Client) New ¶
func (c *Client) New(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
Create a new model. DEPRECATED, use NewModelIn instead.
func (*Client) NewModel ¶
Instantiate a new model, setting the necessary fields, like the client. If key is not empty that key will be used, otherwise Riak will choose a key.
func (*Client) NewModelIn ¶
func (c *Client) NewModelIn(bucketname string, key string, dest Resolver, options ...map[string]uint32) (err error)
Create a new Document Model, passing in the bucketname and key. The key can be empty in which case Riak will pick a key. The destination must be a pointer to a struct that has the riak.Model field. If the bucketname is empty the default bucketname, based on the riak.Model tag will be used.
func (*Client) NewObjectIn ¶
func (c *Client) NewObjectIn(bucketname string, key string, options ...map[string]uint32) (*RObject, error)
Create a new RObject in a bucket directly, without creating a bucket object first
func (*Client) RunMapReduce ¶
Run a MapReduce query
func (*Client) SaveAs ¶
Save a Document Model to Riak under a new key, if empty a Key will be choosen by Riak
func (*Client) ServerVersion ¶
Get the server version
type Many ¶
type Many []One
Link to many other models
type MapReduce ¶
type MapReduce struct {
// contains filtered or unexported fields
}
An object to build a MapReduce job similar to how the Ruby client can build it by adding different stages.
func NewMapReduce ¶
func NewMapReduce() *MapReduce
Create a MapReduce object that can be used to build a MR query
func (*MapReduce) AddBucket ¶
Add a whole bucket as input. Note that this ONLY works on buckets that have secondary indexes (2i) enabled since listing keys on a bucket without using indexes is dangerous on production clusters.
func (*MapReduce) AddBucketRange ¶
Add a range of keys from one bucket using secondary indexes.
func (*MapReduce) AddIndexRange ¶
func (mr *MapReduce) AddIndexRange(bucket string, index string, start string, end string) (err error)
Add a range of keys using a secondary index.
func (*MapReduce) LinkBucket ¶
func (*MapReduce) MapObjectValue ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Make structs work like a Document Model, similar to how the Ruby based "ripple" gem works. This is done by parsing the JSON data and mapping it to the struct's fields. To enable easy integration with Ruby/ripple projects the struct "tag" feature of Go is used to possibly get around the naming convention differences between Go and Ruby (Uppercase starting letter required for export and typically CamelCase versus underscores). Also it stores the model/struct name as _type in Riak.
For example the following Ruby/Ripple class:
class Device include Ripple::Document property :ip, String property :description, String property :download_enabled, Boolean end
can be mapped to the following Go class:
type Device struct { riak.Model `riak:devices` Download_enabled bool `riak:"download_enabled"` Ip string `riak:"ip"` Description string `riak:"description"` }
Note that it is required to have a riak.Model field. Also if the field name in Ripple is equal the extra tag is not needed, (e.g. if the Ripple class above would have a "property :Ip, String").
func (*Model) GetSiblings ¶
func (*Model) Indexes ¶
Return the object's indexes. This allows an application to set custom secondary indexes on the object for later querying.
func (*Model) SaveAs ¶
Save a Document Model to Riak under a new key, if empty a Key will be choosen by Riak
func (Model) SetKey ¶
Set the Key value, note that this does not save the model, it only changes the data structure
type RObject ¶
type RObject struct { Bucket *Bucket Vclock []byte Key string ContentType string Data []byte Links []Link Meta map[string]string Indexes map[string]string Siblings []Sibling Options []map[string]uint32 // contains filtered or unexported fields }
An RObject is an object or document that is or can be stored in Riak
func NewObjectIn ¶
Create a new RObject in a bucket directly, without creating a bucket object first
func (*RObject) AddLink ¶
Add a link if it is not already in the Links slics, returns false if already present
func (*RObject) Conflict ¶
Returns true if the object was fetched with multiple siblings (AllowMult=true on the bucket)
func (*RObject) LinkTo ¶
Add a link to another object (does not store the object, must explicitly call "Store()")