本文整理匯總了Golang中github.com/basho/riak-go-client.Cluster.Execute方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cluster.Execute方法的具體用法?Golang Cluster.Execute怎麽用?Golang Cluster.Execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/basho/riak-go-client.Cluster
的用法示例。
在下文中一共展示了Cluster.Execute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: storeRufus
func storeRufus(cluster *riak.Cluster) {
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("WOOF!"),
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("animals").
WithBucket("dogs").
WithKey("rufus").
WithContent(obj).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
svc := cmd.(*riak.StoreValueCommand)
rsp := svc.Response
fmt.Println(rsp.VClock)
}
示例2: storeQuote
func storeQuote(cluster *riak.Cluster) {
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("I have nothing to declare but my genius"),
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("quotes").
WithBucket("oscar_wilde").
WithKey("genius").
WithContent(obj).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
svc := cmd.(*riak.StoreValueCommand)
rsp := svc.Response
fmt.Println(rsp.VClock)
}
示例3: storeCar
func storeCar(cluster *riak.Cluster) {
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("vroom"),
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("cars").
WithBucket("dodge").
WithKey("viper").
WithW(3).
WithContent(obj).
WithReturnBody(true).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
}
示例4: insertingObjects
func insertingObjects(cluster *riak.Cluster) error {
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
BucketType: "indexes",
Bucket: "users",
Key: "john_smith",
Value: []byte("…user data…"),
}
obj.AddToIndex("twitter_bin", "jsmith123")
obj.AddToIndex("email_bin", "[email protected]")
cmd, err := riak.NewStoreValueCommandBuilder().
WithContent(obj).
Build()
if err != nil {
return err
}
if err := cluster.Execute(cmd); err != nil {
return err
}
return nil
}
示例5: storeStray
func storeStray(cluster *riak.Cluster) {
// There is not a default content type for an object, so it must be defined. For JSON content
// types, please use 'application/json'
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("Found in alley."),
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("animals").
WithBucket("dogs").
WithContent(obj).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
svc := cmd.(*riak.StoreValueCommand)
rsp := svc.Response
fmt.Println(rsp.GeneratedKey)
}
示例6: resolveUsingResolver
func resolveUsingResolver(cluster *riak.Cluster) error {
// Note: a more sophisticated resolver would
// look into the objects to pick one, or perhaps
// present the list to a user to choose
cr := &FirstSiblingResolver{}
cmd, err := riak.NewFetchValueCommandBuilder().
WithBucketType("siblings").
WithBucket("nickelodeon").
WithKey("best_character").
WithConflictResolver(cr).
Build()
if err != nil {
return err
}
err = cluster.Execute(cmd)
if err != nil {
return err
}
fcmd := cmd.(*riak.FetchValueCommand)
// Test that the resolver just returned one riak.Object
vlen := len(fcmd.Response.Values)
if vlen != 1 {
return fmt.Errorf("expected 1 object, got %v", vlen)
}
obj := fcmd.Response.Values[0]
return storeObject(cluster, obj)
}
示例7: incorrectDataType
func incorrectDataType(cluster *riak.Cluster) error {
obj := &riak.Object{
BucketType: "indexes",
Bucket: "people",
Key: "larry",
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("My name is Larry"),
}
obj.AddToIndex("field2_int", "bar")
cmd, err := riak.NewStoreValueCommandBuilder().
WithContent(obj).
Build()
if err != nil {
return err
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println("[DevUsing2i] index data type error:", err)
} else {
return errors.New("[DevUsing2i] expected an error!")
}
return nil
}
示例8: storeCoach
func storeCoach(cluster *riak.Cluster) {
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("Pete Carroll"),
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("siblings").
WithBucket("coaches").
WithKey("seahawks").
WithContent(obj).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
fmt.Println("Stored Pete Carroll")
}
示例9: doPaginatedQuery
func doPaginatedQuery(cluster *riak.Cluster, continuation []byte) error {
builder := riak.NewSecondaryIndexQueryCommandBuilder().
WithBucketType("indexes").
WithBucket("tweets").
WithIndexName("hashtags_bin").
WithRange("ri", "ru").
WithMaxResults(5)
if continuation != nil && len(continuation) > 0 {
builder.WithContinuation(continuation)
}
cmd, err := builder.Build()
if err != nil {
return err
}
if err := cluster.Execute(cmd); err != nil {
return err
}
printIndexQueryResults(cmd)
sciq := cmd.(*riak.SecondaryIndexQueryCommand)
if sciq.Response == nil {
return errors.New("[DevUsing2i] expected response but did not get one")
}
rc := sciq.Response.Continuation
if rc != nil && len(rc) > 0 {
return doPaginatedQuery(cluster, sciq.Response.Continuation)
}
return nil
}
示例10: storeAndUpdateSport
func storeAndUpdateSport(cluster *riak.Cluster) {
obj := &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: []byte("Washington Generals"),
}
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("sports").
WithBucket("nba").
WithKey("champion").
WithContent(obj).
WithReturnBody(true).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
svc := cmd.(*riak.StoreValueCommand)
rsp := svc.Response
obj = rsp.Values[0]
obj.Value = []byte("Harlem Globetrotters")
cmd, err = riak.NewStoreValueCommandBuilder().
WithBucketType("sports").
WithBucket("nba").
WithKey("champion").
WithContent(obj).
WithReturnBody(true).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
svc = cmd.(*riak.StoreValueCommand)
rsp = svc.Response
obj = rsp.Values[0]
fmt.Printf("champion: %v\n", string(obj.Value))
}
示例11: storeBucketProperties
func storeBucketProperties(cluster *riak.Cluster) error {
cmd, err := riak.NewStoreBucketPropsCommandBuilder().
WithBucketType("animals").
WithBucket("cats").
WithSearchIndex("famous").
Build()
if err != nil {
return err
}
return cluster.Execute(cmd)
}
示例12: InitIndexBucket
func InitIndexBucket(cluster *riak.Cluster, bucket string) {
cmd, err := riak.NewStoreBucketPropsCommandBuilder().
WithBucket(bucket).
WithAllowMult(true).
Build()
if err != nil {
logError("initIndexBucket", "Error creating command for setting up bucket for \"allow_mult\"", err.Error())
}
if err = cluster.Execute(cmd); err != nil {
logError("initIndexBucket", "Error setting up bucket for \"allow_mult\"", err.Error())
}
}
示例13: storeIndex
func storeIndex(cluster *riak.Cluster) error {
cmd, err := riak.NewStoreIndexCommandBuilder().
WithIndexName("famous").
WithSchemaName("_yz_default").
WithTimeout(time.Second * 30).
Build()
if err != nil {
return err
}
return cluster.Execute(cmd)
}
示例14: storeObject
func storeObject(cluster *riak.Cluster, obj *riak.Object) error {
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("siblings").
WithBucket("nickelodeon").
WithKey("best_character").
WithContent(obj).
Build()
if err != nil {
return err
}
return cluster.Execute(cmd)
}
示例15: fetchChampion
func fetchChampion(cluster *riak.Cluster) {
cmd, err := riak.NewFetchValueCommandBuilder().
WithBucketType("sports").
WithBucket("nba").
WithKey("champion").
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
fvc := cmd.(*riak.FetchValueCommand)
rsp := fvc.Response
var obj *riak.Object
if len(rsp.Values) > 0 {
obj = rsp.Values[0]
} else {
obj = &riak.Object{
ContentType: "text/plain",
Charset: "utf-8",
ContentEncoding: "utf-8",
Value: nil,
}
}
obj.Value = []byte("Harlem Globetrotters")
cmd, err = riak.NewStoreValueCommandBuilder().
WithBucketType("sports").
WithBucket("nba").
WithContent(obj).
Build()
if err != nil {
fmt.Println(err.Error())
return
}
if err := cluster.Execute(cmd); err != nil {
fmt.Println(err.Error())
return
}
}