本文整理匯總了Golang中github.com/basho/riak-go-client.Cluster.ExecuteAsync方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cluster.ExecuteAsync方法的具體用法?Golang Cluster.ExecuteAsync怎麽用?Golang Cluster.ExecuteAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/basho/riak-go-client.Cluster
的用法示例。
在下文中一共展示了Cluster.ExecuteAsync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: storeObjects
func storeObjects(cluster *riak.Cluster) error {
o1 := &riak.Object{
Key: "liono",
Value: []byte("{\"name_s\":\"Lion-o\",\"age_i\":30,\"leader_b\":true}"),
}
o2 := &riak.Object{
Key: "cheetara",
Value: []byte("{\"name_s\":\"Cheetara\",\"age_i\":30,\"leader_b\":false}"),
}
o3 := &riak.Object{
Key: "snarf",
Value: []byte("{\"name_s\":\"Snarf\",\"age_i\":43,\"leader_b\":false}"),
}
o4 := &riak.Object{
Key: "panthro",
Value: []byte("{\"name_s\":\"Panthro\",\"age_i\":36,\"leader_b\":false}"),
}
objs := [...]*riak.Object{o1, o2, o3, o4}
wg := &sync.WaitGroup{}
for _, obj := range objs {
obj.ContentType = "application/json"
obj.Charset = "utf-8"
obj.ContentEncoding = "utf-8"
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("animals").
WithBucket("cats").
WithContent(obj).
Build()
if err != nil {
return err
}
args := &riak.Async{
Command: cmd,
Wait: wg,
}
if err := cluster.ExecuteAsync(args); err != nil {
return err
}
}
wg.Wait()
return nil
}
示例2: queryingRange
func queryingRange(cluster *riak.Cluster) error {
c1, c1err := riak.NewSecondaryIndexQueryCommandBuilder().
WithBucketType("indexes").
WithBucket("people").
WithIndexName("field1_bin").
WithRange("val2", "val4").
Build()
if c1err != nil {
return c1err
}
c2, c2err := riak.NewSecondaryIndexQueryCommandBuilder().
WithBucketType("indexes").
WithBucket("people").
WithIndexName("field2_int").
WithIntRange(1002, 1004).
Build()
if c2err != nil {
return c2err
}
wg := &sync.WaitGroup{}
cmds := [...]riak.Command{c1, c2}
for _, cmd := range cmds {
args := &riak.Async{
Command: cmd,
Wait: wg,
}
if err := cluster.ExecuteAsync(args); err != nil {
return err
}
}
wg.Wait()
for _, cmd := range cmds {
printIndexQueryResults(cmd)
}
return nil
}
示例3: indexingObjects
func indexingObjects(cluster *riak.Cluster) error {
o1 := &riak.Object{
Key: "larry",
Value: []byte("My name is Larry"),
}
o1.AddToIndex("field1_bin", "val1")
o1.AddToIntIndex("field2_int", 1001)
o2 := &riak.Object{
Key: "moe",
Value: []byte("My name is Moe"),
}
o2.AddToIndex("Field1_bin", "val2")
o2.AddToIntIndex("Field2_int", 1002)
o3 := &riak.Object{
Key: "curly",
Value: []byte("My name is Curly"),
}
o3.AddToIndex("FIELD1_BIN", "val3")
o3.AddToIntIndex("FIELD2_INT", 1003)
o4 := &riak.Object{
Key: "veronica",
Value: []byte("My name is Veronica"),
}
o4.AddToIndex("FIELD1_bin", "val4")
o4.AddToIndex("FIELD1_bin", "val4")
o4.AddToIndex("FIELD1_bin", "val4a")
o4.AddToIndex("FIELD1_bin", "val4b")
o4.AddToIntIndex("FIELD2_int", 1004)
o4.AddToIntIndex("FIELD2_int", 1005)
o4.AddToIntIndex("FIELD2_int", 1006)
o4.AddToIntIndex("FIELD2_int", 1004)
o4.AddToIntIndex("FIELD2_int", 1004)
o4.AddToIntIndex("FIELD2_int", 1007)
objs := [...]*riak.Object{o1, o2, o3, o4}
wg := &sync.WaitGroup{}
for _, obj := range objs {
obj.ContentType = "text/plain"
obj.Charset = "utf-8"
obj.ContentEncoding = "utf-8"
cmd, err := riak.NewStoreValueCommandBuilder().
WithBucketType("indexes").
WithBucket("people").
WithContent(obj).
Build()
if err != nil {
return err
}
args := &riak.Async{
Command: cmd,
Wait: wg,
}
if err := cluster.ExecuteAsync(args); err != nil {
return err
}
}
wg.Wait()
return nil
}