Skip to content

Instantly share code, notes, and snippets.

@Vagabond
Created August 6, 2014 00:35
Show Gist options
  • Select an option

  • Save Vagabond/3c116dec551245ba8899 to your computer and use it in GitHub Desktop.

Select an option

Save Vagabond/3c116dec551245ba8899 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/tpjg/goriakpbc"
)
func main() {
err := riak.ConnectClient("127.0.0.1:8087")
if err != nil {
fmt.Println("Cannot connect, is Riak running?")
return
}
bucket, err := riak.NewBucketType("counters", "tstriak")
if err != nil {
fmt.Printf("could not create bucket", err)
}
obj, err := bucket.FetchCounter("tstobj2")
if obj == nil {
fmt.Printf("could not read", err)
return
}
fmt.Printf("value %d\n", obj.GetValue())
obj.Increment(5)
obj.Store()
obj, err = bucket.FetchCounter("tstobj2")
if obj == nil {
fmt.Printf("could not read", err)
return
}
fmt.Printf("value %d\n", obj.GetValue())
obj.Increment(-5)
obj.Store()
obj, err = bucket.FetchCounter("tstobj2")
if obj == nil {
fmt.Printf("could not read", err)
return
}
fmt.Printf("value %d\n", obj.GetValue())
bucket, err = riak.NewBucketType("sets", "tstriak")
if err != nil {
fmt.Printf("could not create bucket", err)
}
obj2, err := bucket.FetchSet("tstobj2")
if obj2 == nil {
fmt.Printf("could not read", err)
return
}
fmt.Printf("value %#v\n", obj2.GetValue())
obj2.Add([]byte("hello"))
obj2.Store()
obj2, err = bucket.FetchSet("tstobj2")
if obj2 == nil {
fmt.Printf("could not read", err)
return
}
fmt.Printf("value %#v\n", obj2.GetValue())
obj2.Remove([]byte("hello"))
obj2.Store()
obj2, err = bucket.FetchSet("tstobj2")
if obj2 == nil {
fmt.Printf("could not read", err)
return
}
fmt.Printf("value %#v\n", obj2.GetValue())
riak.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment