Documentation ¶
Overview ¶
Package goriak is a Golang driver for Riak KV. Goriak offers simple ways of binding your Go datatypes and values to Riak.
Goriaks specially is dealing with Riak KV Data Types (http://docs.basho.com/riak/kv/2.1.4/developing/data-types/) and allowing Marshal/Unmarshal of Go structs into Riak Maps.
Index ¶
- func NewMapOperation() riak.MapOperation
- type Command
- func (c Command) AddToIndex(key, value string) Command
- func (c Command) AllKeys(callback func([]string) error) Command
- func (c Command) ConflictResolver(fn func([]ConflictObject) ResolvedConflict) Command
- func (c Command) Delete(key string) Command
- func (c Command) Get(key string, output interface{}) Command
- func (c Command) GetJSON(key string, output interface{}) Command
- func (c Command) GetRaw(key string, output *[]byte) Command
- func (c Command) IndexContinuation(continuation []byte) Command
- func (c Command) Key(key string) Command
- func (c Command) KeysInIndex(indexName, indexValue string, callback func(SecondaryIndexQueryResult)) Command
- func (c Command) Limit(limit uint32) Command
- func (c Command) MapOperation(op riak.MapOperation, context []byte) Command
- func (c Command) Run(session *Session) (*Result, error)
- func (c Command) Set(val interface{}) Command
- func (c Command) SetJSON(value interface{}) Command
- func (c Command) SetRaw(value []byte) Command
- func (c Command) VClock(vclock []byte) Command
- func (c Command) WithDw(dw uint32) Command
- func (c Command) WithPr(pr uint32) Command
- func (c Command) WithPw(pw uint32) Command
- func (c Command) WithR(r uint32) Command
- func (c Command) WithRw(rw uint32) Command
- func (c Command) WithW(w uint32) Command
- type ConflictObject
- type ConflictResolver
- type ConnectOpts
- type Counter
- type Flag
- type Register
- func (r *Register) Exec(client *Session) error
- func (r Register) MarshalJSON() ([]byte, error)
- func (r *Register) Set(val []byte) *Register
- func (r *Register) SetString(val string) *Register
- func (r *Register) String() string
- func (r *Register) UnmarshalJSON(data []byte) error
- func (r *Register) Value() []byte
- type ResolvedConflict
- type Result
- type SecondaryIndexQueryResult
- type Session
- type Set
- func (s *Set) Add(add []byte) *Set
- func (s *Set) AddString(add string) *Set
- func (s *Set) Exec(client *Session) error
- func (s *Set) Has(search []byte) bool
- func (s *Set) HasString(search string) bool
- func (s Set) MarshalJSON() ([]byte, error)
- func (s *Set) Remove(remove []byte) *Set
- func (s *Set) RemoveString(remove string) *Set
- func (s *Set) Strings() []string
- func (s *Set) UnmarshalJSON(data []byte) error
- func (s *Set) Value() [][]byte
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMapOperation ¶
func NewMapOperation() riak.MapOperation
NewMapOperation returns a new riak.MapOperation that you can for advanced Riak operations
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command is the main query builder object
func Bucket ¶
Bucket specifies the bucket and bucket type that your following command will be performed on.
func (Command) AddToIndex ¶
func (Command) AllKeys ¶
AllKeys returns all keys in the set bucket. The response will be sent in multiple batches to callback
func (Command) ConflictResolver ¶ added in v2.3.0
func (c Command) ConflictResolver(fn func([]ConflictObject) ResolvedConflict) Command
func (Command) Get ¶
Get retreives a Map from Riak. Get performs automatic conversion from Riak Maps to your Go datatype. See Set() for more information.
func (Command) GetRaw ¶
GetRaw retreives key as a []byte. The output will be written to output by Run().
func (Command) IndexContinuation ¶ added in v2.4.1
func (Command) Key ¶
Key specifies the Riak key that following commands such as Get() and MapOperation()
func (Command) KeysInIndex ¶
func (c Command) KeysInIndex(indexName, indexValue string, callback func(SecondaryIndexQueryResult)) Command
KeysInIndex returns all keys in the index indexName that has the value indexValue The values will be returned to the callbak function When all keys have been returned SecondaryIndexQueryResult.IsComplete will be true
func (Command) MapOperation ¶
func (c Command) MapOperation(op riak.MapOperation, context []byte) Command
MapOperation takes a riak.MapOperation so that you can run custom commands on your Riak Maps
func (Command) Run ¶
Run performs the action built in Command and runs it against the Riak connection specified by Session.
func (Command) Set ¶
Set automatically converts your Go datatype to the equivalent type in Riak
| Go Type | Riak Type | |------------|-----------| | struct | map | | string | register | | [n]byte | register | | []byte | register | | []slice | set | | []slice | set | | [][]byte | set | | map | map | | time.Time | register |
func (Command) SetJSON ¶
SetJSON saves value as key in the bucket bucket/bucketType Values can automatically be added to indexes with the struct tag goriakindex
func (Command) SetRaw ¶
SetRaw allows you to set a []byte directly to Riak. SetRaw gives you full control of the data stored, compared to SetJSON and Set.
func (Command) WithDw ¶ added in v2.1.0
WithDw sets the amount of nodes required to report successfully writes to backend storage. Used with Set(), SetRaw(), SetJSON(), and Delete()
func (Command) WithPr ¶ added in v2.1.0
WithPr sets the amount of primary nodes required to report back during reads. Used with Get(), GetRaw(), GetJSON(), and Delete().
func (Command) WithPw ¶ added in v2.1.0
WithPw sets the amount of primary nodes required to report back during writes. Used with Set(), SetRaw(), SetJSON(), and Delete().
func (Command) WithR ¶ added in v2.1.0
WithR sets the amount of nodes required to report back during reads. Used with Get(), GetRaw(), GetJSON(), and Delete().
type ConflictObject ¶ added in v2.3.0
func (ConflictObject) GetResolved ¶ added in v2.3.0
func (r ConflictObject) GetResolved() ResolvedConflict
GetResolved creates a ResolvedConflict object
type ConflictResolver ¶ added in v2.3.0
type ConflictResolver interface {
ConflictResolver([]ConflictObject) ResolvedConflict
}
The ConflictResolver interface is used to solve conflicts when using Get() and GetJSON(). All versions will be sent to your ConflictResolver method. Return the (merged) version that you want to keep.
Example ¶
// For this to work you need to activate allow_mult on your bucket type // http://docs.basho.com/riak/kv/2.2.0/developing/usage/conflict-resolution/ session, _ := Connect(ConnectOpts{ Address: "127.0.0.1", }) key := "object-1" // Save the same object without using .VClock() causing a conflict _, err := Bucket("bucket", "tests").Key(key).SetJSON("hello").Run(session) if err != nil { log.Println(err) } _, err = Bucket("bucket", "tests").Key(key).SetJSON("worlds of conflicts!").Run(session) if err != nil { log.Println(err) } // Our conflict resolver object resolver := func(objs []ConflictObject) ResolvedConflict { // Decide how to pick the result. We'll use len() to pick the longest value var maxObject ConflictObject var maxValue int for _, o := range objs { if len(o.Value) > maxValue { maxObject = o maxValue = len(o.Value) } } // Convert directly to a ResolvedConflict object return maxObject.GetResolved() } // Get your object var res string _, err = Bucket("bucket", "tests"). ConflictResolver(resolver). GetJSON(key, &res). Run(session) if err != nil { log.Println(err) } // res will now contain the longest value log.Println(res)
Output:
type ConnectOpts ¶
type ConnectOpts struct { // Both Address and Addresses should be on the form HOST|IP[:PORT] Address string // Address to a single Riak host. Will be used in case Addresses is empty Addresses []string // Addresses to all Riak hosts. }
ConnectOpts are the available options for connecting to your Riak instance
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a wapper to handle Riak Counters Counter needs to be initialized by GetMap() to fully function
func NewCounter ¶
func NewCounter() *Counter
NewCounter returns a partial Counter Counters returned by NewCounter() can only be updated with SetMap(). Counter.Exec() will not work on counters returned by NewCounter()
func (*Counter) Exec ¶
Exec saves changes made to the Counter to Riak Exec only works on Counters initialized by GetMap() If the commad succeeds the counter will be updated with the value in the response from Riak
func (*Counter) Increase ¶
Increase the value in the Counter by i The value in Counter.Value() will be updated directly Increase() will not save the changes to Riak directly
func (Counter) MarshalJSON ¶ added in v2.4.1
MarshalJSON satisfies the JSON interface
func (*Counter) UnmarshalJSON ¶ added in v2.4.1
UnmarshalJSON satisfies the JSON interface
type Flag ¶ added in v2.3.0
type Flag struct {
// contains filtered or unexported fields
}
func (Flag) MarshalJSON ¶ added in v2.4.1
MarshalJSON satisfies the JSON interface
func (*Flag) UnmarshalJSON ¶ added in v2.4.1
UnmarshalJSON satisfies the JSON interface
type Register ¶ added in v2.3.0
type Register struct {
// contains filtered or unexported fields
}
func NewRegister ¶ added in v2.3.0
func NewRegister() *Register
func (Register) MarshalJSON ¶ added in v2.4.1
MarshalJSON satisfies the JSON interface
func (*Register) UnmarshalJSON ¶ added in v2.4.1
UnmarshalJSON satisfies the JSON interface
type ResolvedConflict ¶ added in v2.3.0
type Result ¶
type Result struct { NotFound bool // Wether or not the item was not found when using Get, GetJSON, or GetRaw. Key string // Returns your automatically generated key when using Set, SetJSON, or SetRaw. Context []byte // Returns the Riak Context used in map operations. Is set when using Get. VClock []byte Continuation []byte // Continuation in case of SecondaryIndex queries }
Result contains your query result data from Run()
type SecondaryIndexQueryResult ¶
SecondaryIndexQueryResult is the items sent to the callback function used by KeysInIndex
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session holds the connection to Riak
func Connect ¶
func Connect(opts ConnectOpts) (*Session, error)
Connect creates a new Riak connection. See ConnectOpts for the available options.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a special type to make it easier to work with Riak Sets in Go.
Example ¶
session, _ := Connect(ConnectOpts{ Address: "127.0.0.1", }) type Article struct { Tags *Set Context []byte `goriak:"goriakcontext"` } // Initializing a new Article and the Set within art := Article{ Tags: NewSet(), } riakKey := "article-1" // Adding the tags "one" and "two" art.Tags.AddString("one") art.Tags.AddString("two") _, err := Bucket("bucket", "bucketType").Key(riakKey).Set(art).Run(session) if err != nil { // .. } // Retreiving from Riak var getArt Article _, err = Bucket("bucket", "bucketType").Get(riakKey, &getArt).Run(session) if err != nil { // .. } // Adding one extra tag. // Multiple AddString() and RemoveString() can be chained together before calling Exec(). err = getArt.Tags.AddString("three").Exec(session) if err != nil { // .. }
Output:
func NewSet ¶
func NewSet() *Set
NewSet returnes a new and empty Set. Sets returned from NewSet() can not be used with Set.Exec()
func (*Set) Add ¶
Add adds an item to the direct value of the Set. Save the changes to Riak with Set.Exec() or SetMap().
func (Set) MarshalJSON ¶ added in v2.4.0
MarshalJSON satisfies the JSON interface
func (*Set) Remove ¶
Remove deletes an item to the direct value of the Set. Save the changes to Riak with Set.Exec() or SetMap().
func (*Set) RemoveString ¶
RemoveString is a shortcut to Remove
func (*Set) UnmarshalJSON ¶ added in v2.4.0
UnmarshalJSON satisfies the JSON interface