Documentation
¶
Index ¶
- Constants
- Variables
- type AsyncFetch
- type Blob
- type Bucket
- func (b *Bucket) Fetch(o Object, key string) error
- func (b *Bucket) GetCounter(name string) (*Counter, error)
- func (b *Bucket) GetProperties() (*rpbc.RpbBucketProps, error)
- func (b *Bucket) IndexLookup(idx string, val string) (*IndexQueryRes, error)
- func (b *Bucket) IndexRange(idx string, min int64, max int64) (*IndexQueryRes, error)
- func (b *Bucket) MakeCache() error
- func (b *Bucket) MultiFetchAsync(o Duplicator, procs int, keys ...string) <-chan *AsyncFetch
- func (b *Bucket) New(o Object, key *string) error
- func (b *Bucket) NewCounter(name string, start int64) (*Counter, error)
- func (b *Bucket) Overwrite(o Object, key string) error
- func (b *Bucket) Push(o Object) error
- func (b *Bucket) Reset() error
- func (b *Bucket) SetProperties(props *rpbc.RpbBucketProps) error
- func (b *Bucket) Store(o Object) error
- func (b *Bucket) Update(o Object) (bool, error)
- type Client
- func (c *Client) Bucket(name string) *Bucket
- func (c *Client) Close()
- func (c *Client) Delete(o Object, opts *DelOpts) error
- func (c *Client) Fetch(o Object, bucket string, key string, opts *ReadOpts) error
- func (c *Client) FetchHead(bucket string, key string) (*Info, error)
- func (c *Client) GetBucketTypeProperties(typeName string) (*rpbc.RpbBucketProps, error)
- func (c *Client) IndexLookup(bucket string, index string, value string, max *int) (*IndexQueryRes, error)
- func (c *Client) IndexRange(bucket string, index string, min int64, max int64, maxret *int) (*IndexQueryRes, error)
- func (c *Client) New(o Object, bucket string, key *string, opts *WriteOpts) error
- func (c *Client) Overwrite(o Object, bucket string, key string, opts *WriteOpts) error
- func (c *Client) Ping() error
- func (c *Client) PullHead(o Object) error
- func (c *Client) Push(o Object, opts *WriteOpts) error
- func (c *Client) PushChangeset(o Object, chng func(Object) error, opts *WriteOpts) error
- func (c *Client) SetBucketTypeProperties(typeName string, props *rpbc.RpbBucketProps) error
- func (c *Client) Store(o Object, opts *WriteOpts) error
- func (c *Client) Update(o Object, opts *ReadOpts) (bool, error)
- type Counter
- type DelOpts
- type Duplicator
- type ErrMultipleResponses
- type IndexQueryRes
- func (i *IndexQueryRes) Contains(key string) bool
- func (i *IndexQueryRes) FetchAsync(o Duplicator, procs int) <-chan *AsyncFetch
- func (i *IndexQueryRes) FetchNext(o Object) (done bool, err error)
- func (i *IndexQueryRes) Keys() []string
- func (i *IndexQueryRes) Len() int
- func (i *IndexQueryRes) Which(o Object, conds ...func(Object) bool) ([]string, error)
- type Info
- func (in *Info) AddIndex(key string, value string) bool
- func (in *Info) AddIndexInt(key string, value int64) bool
- func (in *Info) AddLink(name string, bucket string, key string) bool
- func (in *Info) AddMeta(key string, value string) bool
- func (in *Info) Bucket() string
- func (in *Info) ContentType() string
- func (in *Info) GetIndex(key string) (val string)
- func (in *Info) GetIndexInt(key string) *int64
- func (in *Info) GetLink(name string) (bucket string, key string)
- func (in *Info) GetMeta(key string) (val string)
- func (in *Info) Indexes() [][2]string
- func (in *Info) Key() string
- func (in *Info) Metas() [][2]string
- func (in *Info) RemoveIndex(key string)
- func (in *Info) RemoveIndexInt(key string)
- func (in *Info) RemoveLink(name string)
- func (in *Info) RemoveMeta(key string)
- func (in *Info) SetContentType(s string)
- func (in *Info) SetIndex(key string, value string)
- func (in *Info) SetIndexInt(key string, value int64)
- func (in *Info) SetLink(name string, bucket string, key string)
- func (in *Info) SetMeta(key string, value string)
- func (in *Info) Vclock() string
- type Object
- type ObjectM
- type ReadOpts
- type RiakError
- type WriteOpts
Constants ¶
const (
DefaultReqTimeout = 500
)
Variables ¶
var ( // ErrClosed is returned when the // an attempt is made to make a request // with a closed clinet ErrClosed = errors.New("client closed") // is unable to successfully dial any // Riak node. ErrUnavail = errors.New("no connection to could be established") )
var ( // ErrUnexpectedResponse is returned when riak returns the wrong // message type ErrUnexpectedResponse = errors.New("unexpected response") // ErrNotFound is returned when // no objects are returned for // a read operation ErrNotFound = errors.New("not found") // ErrDeleted is returned // when the object has been marked // as deleted, but has not yet been reaped ErrDeleted = errors.New("object deleted") )
var ( ErrNoPath = errors.New("bucket and/or key not defined") ErrModified = errors.New("object has been modified since last read") ErrExists = errors.New("object already exists") )
var (
ErrDone = errors.New("done")
)
Functions ¶
This section is empty.
Types ¶
type AsyncFetch ¶
AsyncFetch represents the output of an asynchronous fetch operation. 'Value' is never nil, but 'Error' may or may not be nil. If 'Error' is non-nil, then 'Value' is usually the zero value of the underlying object.
type Blob ¶
Blob is a generic riak key/value container that implements the Object interface.
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket represents a Riak bucket
func (*Bucket) GetCounter ¶
GetCounter gets a counter.
func (*Bucket) GetProperties ¶
func (b *Bucket) GetProperties() (*rpbc.RpbBucketProps, error)
GetProperties retreives the properties of the bucket
func (*Bucket) IndexLookup ¶
func (b *Bucket) IndexLookup(idx string, val string) (*IndexQueryRes, error)
IndexLookup performs a secondary index query on the bucket
func (*Bucket) IndexRange ¶
IndexRange performs a secondary index range query on the bucket
func (*Bucket) MakeCache ¶
MakeCache makes a memory-backed cache bucket. You will most likely need the following options enabled in your riak.conf:
# this enables multiple backends storage_backend = multi # this creates a backend called 'cache' backed by RAM multi_backend.cache.storage_backend = memory # this makes a backend called 'std' and sets its storage backend # (you can name this one whatever you would like) multi_backend.std.storage_backend = <leveldb OR bitcask> multi_backend.default = std
MakeCache will error if your configuration is incorrect.
NB: keep in mind that this bucket will only be backed by RAM and uses no replication. This bucket should only be used to store ephemeral objects.
func (*Bucket) MultiFetchAsync ¶
func (b *Bucket) MultiFetchAsync(o Duplicator, procs int, keys ...string) <-chan *AsyncFetch
MultiFetchAsync returns fetch results as a future. Results may return in any order. Every result on the channel will have its "Value" field type-assertable to the underlying type of 'o'. 'procs' goroutines will be used for fetching.
func (*Bucket) NewCounter ¶
NewCounter creates a new counter with an optional starting value. If the counter already exists, the value returned will be the existing value plus "start".
func (*Bucket) SetProperties ¶
func (b *Bucket) SetProperties(props *rpbc.RpbBucketProps) error
SetProperties sets the properties of the bucket
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a pool of connections to a Riak cluster.
func Dial ¶
Dial creates a client connected to one or many Riak nodes. The client will attempt to avoid using downed nodes. Dial returns an error if it is unable to reach a good node.
func (*Client) Fetch ¶
Fetch puts whatever exists at the provided bucket+key into the provided Object. It has undefined behavior if the object supplied does not know how to unmarshal the bytes returned from riak.
func (*Client) FetchHead ¶
FetchHead returns the head (*Info) of an object stored in Riak. This is the least expensive way to check for the existence of an object.
func (*Client) GetBucketTypeProperties ¶
func (c *Client) GetBucketTypeProperties(typeName string) (*rpbc.RpbBucketProps, error)
GetBucketTypeProperties gets the bucket properties associated with a given bucket type. *NOTE* bucket types are a Riak 2.0 feature.
func (*Client) IndexLookup ¶
func (c *Client) IndexLookup(bucket string, index string, value string, max *int) (*IndexQueryRes, error)
IndexLookup returns the keys that match the index-value pair specified. You can specify the maximum number of returned keys ('max'). Index queries are performed in "streaming" mode.
func (*Client) IndexRange ¶
func (c *Client) IndexRange(bucket string, index string, min int64, max int64, maxret *int) (*IndexQueryRes, error)
IndexRange returns the keys that match the index range query. You can specify the maximum number of returned results ('max'). Index queries are performed in "streaming" mode.
func (*Client) New ¶
New writes a new object into the database. If 'key' is non-nil, New will attempt to use that key, and return ErrExists if an object already exists at that key-bucket pair. Riak will assign this object a key if 'key' is nil.
func (*Client) Overwrite ¶
Overwrite performs a store operation on an arbitrary location. It does not send a vclock, and the object itself is not modified. Overwrite ignores NotFound errors. This function is only safe to use with buckets in which "last_write_wins" is turned on. Ideally, this function is only used for caches.
func (*Client) PullHead ¶
PullHead pulls the latest object metadata into the object. The Info() pointed to by the object will be changed if the object has been changed in Riak since the last read. If you want to read the entire object, use Update() instead.
func (*Client) Push ¶
Push makes a conditional (if-not-modified) write to the database. This is the recommended way of making writes to the database, as it minimizes the chances of producing sibling objects.
func (*Client) PushChangeset ¶
PushChangeset pushes a changeset to an object, handling the case in which the object has been updated in the database since the last local fetch. The 'chng' function should check if the change that it wanted already happened, and return ErrDone in that case. The 'chng' function is allowed to type-assert its argument to the underlying type of 'o'.
func (*Client) SetBucketTypeProperties ¶
func (c *Client) SetBucketTypeProperties(typeName string, props *rpbc.RpbBucketProps) error
SetBucketTypeProperties sets the bucket properties associated with a given bucket type. *NOTE* bucket types are a Riak 2.0 feature.
func (*Client) Store ¶
Store makes a basic write to the database. Store will return ErrNoPath if the object does not already have a key and bucket defined. (Use New() if this object isn't already in the database.)
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a Riak CRDT that acts as a distributed counter. Counters only work in buckets with 'allow_mult' turned on.
type DelOpts ¶
type DelOpts struct {
R *uint32 // required reads
W *uint32 // required writes
PR *uint32 // required primary node reads
PW *uint32 // required primary node writes
RW *uint32 // required replica deletions
DW *uint32 // required durable (to disk) writes
}
DelOpts are options available on delete operations. All values are optional.
type Duplicator ¶
type Duplicator interface {
Object
// Empty should return an initialized
// (zero-value) object of the same underlying
// type as the parent.
NewEmpty() Object
}
Duplicator types know how to return an empty copy of themselves, on top of fulfilling the Object interface.
type ErrMultipleResponses ¶
ErrMultipleResponses is the type of error returned when multiple siblings are retrieved for an object.
func (*ErrMultipleResponses) Error ¶
func (m *ErrMultipleResponses) Error() string
type IndexQueryRes ¶
type IndexQueryRes struct {
// contains filtered or unexported fields
}
IndexQueryRes is the response to a secondary index query.
func (*IndexQueryRes) Contains ¶
func (i *IndexQueryRes) Contains(key string) bool
Contains returns whether or not the query response contains this particular key
func (*IndexQueryRes) FetchAsync ¶
func (i *IndexQueryRes) FetchAsync(o Duplicator, procs int) <-chan *AsyncFetch
FetchAsync returns a channel on which all of the objects in the query are returned. 'procs' determines the number of goroutines actively fetching. The channel will be closed once all the objects have been returned. Objects are fetched asynchronously. The (underlying) type of every object returned in each AsyncFetch is the same as returned from o.NewEmpty().
func (*IndexQueryRes) FetchNext ¶
func (i *IndexQueryRes) FetchNext(o Object) (done bool, err error)
Fetch fetches the next object in the query. Fetch returns whether or not there are objects remaining in the query result, and any error encountered in fetching that object.
func (*IndexQueryRes) Keys ¶
func (i *IndexQueryRes) Keys() []string
Keys returns the complete list of response keys
func (*IndexQueryRes) Len ¶
func (i *IndexQueryRes) Len() int
Len returns the number of keys in the response
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info contains information about a specific Riak object. You can use it to satisfy the Object interface. Info's zero value (Info{}) is valid. You can use the Info object to add links, seconary indexes, and user metadata to the object referencing this Info object. Calls to Fetch(), Push(), Store(), New(), etc. will changes the contents of this struct.
func (*Info) AddIndex ¶
Add adds a key-value pair to an Indexes object, but returns false if a key already exists under that name and has a different value. Returns true if the index already has this exact key-value pair, or if the pair is written in with no conflicts. (All XxxIndex operations append "_bin" to key values internally in order to comply with the Riak secondary index specification, so the user does not have to include it.)
func (*Info) AddIndexInt ¶
AddIndexInt sets an integer secondary index value using the same conditional rules as AddIndex
func (*Info) AddLink ¶
AddLink adds a link conditionally. It returns true if the value was already set to this bucket-key pair, or if no value existed at 'name'. It returns false otherwise.
func (*Info) GetIndexInt ¶
GetIndexInt gets an integer index value
func (*Info) Indexes ¶
Indexes returns a list of all of the key-value pairs in this object. (Key first, then value.) Note that string-string indexes will have keys postfixed with "_bin", and string-int indexes will have keys postfixed with "_int", per the Riak secondary index specification.
func (*Info) RemoveIndex ¶
RemoveIndex removes a key from the object
func (*Info) RemoveIndexInt ¶
RemoveIndexInt removes an integer index key from an object
func (*Info) RemoveLink ¶
RemoveLink removes a link (if it exists)
func (*Info) RemoveMeta ¶
RemoveMeta deletes the meta value at a key
func (*Info) SetContentType ¶
SetContentType sets the content-type to 's'.
func (*Info) SetIndexInt ¶
SetIndexInt sets a integer secondary index value
type Object ¶
type Object interface {
// Objects must maintain
// a reference to an Info
// struct, which contains
// this object's riak
// metadata. Info() must
// never return nil, or it
// will cause a panic.
Info() *Info
// Marshal should return the encoded
// value of the object, and any
// relevant errors.
Marshal() ([]byte, error)
// Unmarshal should unmarshal the object
// from a []byte. It can safely use
// zero-copy methods, as the byte slice
// passed to it will "belong" to the
// object.
Unmarshal([]byte) error
}
Object is the interface that must be satisfied in order to fetch or store an object in Riak.
type ObjectM ¶
type ObjectM interface {
Duplicator
// Merge should merge the argument object into the method receiver. It
// is safe to type-assert the argument of Merge to the same type
// as the type of the object satisfying the inteface. (Under the hood,
// the argument passed to Merge is simply the value of NewEmpty() after
// data has been read into it.) Merge is used to iteratively merge many sibling objects.
Merge(o Object)
}
ObjectM is an object that also knows how to merge itself with siblings. If an object has this interface defined, this package will use the Merge method to transparently handle siblings returned from Riak.
type ReadOpts ¶
type ReadOpts struct {
R *uint32 // number of reads
Pr *uint32 // number of primary replica reads
BasicQuorum *bool // basic quorum required
SloppyQuorum *bool // sloppy quorum required
NotfoundOk *bool // treat not-found as a read for 'R'
NVal *uint32 // 'n_val'
}
ReadOpts are read options that can be specified when doing a read operation. All of these default to the default bucket properties.

