• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang riak-go-client.Cluster类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/basho/riak-go-client.Cluster的典型用法代码示例。如果您正苦于以下问题:Golang Cluster类的具体用法?Golang Cluster怎么用?Golang Cluster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Cluster类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:35,代码来源:main.go


示例2: 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
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:27,代码来源:main.go


示例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
	}
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:27,代码来源:main.go


示例4: 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")
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:27,代码来源:main.go


示例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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:30,代码来源:main.go


示例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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:32,代码来源:main.go


示例7: 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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:29,代码来源:main.go


示例8: 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
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:27,代码来源:main.go


示例9: 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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:29,代码来源:main.go


示例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))
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:54,代码来源:main.go


示例11: 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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:12,代码来源:main.go


示例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())
	}
}
开发者ID:PeerioTechnologies,项目名称:chronicler,代码行数:12,代码来源:buckets.go


示例13: 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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:12,代码来源:main.go


示例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)
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:13,代码来源:main.go


示例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
	}
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:49,代码来源:main.go


示例16: doAndSearchRequest

func doAndSearchRequest(cluster *riak.Cluster) error {
	cmd, err := riak.NewSearchCommandBuilder().
		WithIndexName("famous").
		WithQuery("leader_b:true AND age_i:[30 TO *]").
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	return printDocs(cmd, "AND Search Documents:")
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:15,代码来源:main.go


示例17: 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
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:48,代码来源:main.go


示例18: queryingRangeWithTerms

func queryingRangeWithTerms(cluster *riak.Cluster) error {
	cmd, err := riak.NewSecondaryIndexQueryCommandBuilder().
		WithBucketType("indexes").
		WithBucket("tweets").
		WithIndexName("hashtags_bin").
		WithRange("rock", "rocl").
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	printIndexQueryResults(cmd)
	return nil
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:18,代码来源:main.go


示例19: queryingIndexes

func queryingIndexes(cluster *riak.Cluster) error {
	cmd, err := riak.NewSecondaryIndexQueryCommandBuilder().
		WithBucketType("indexes").
		WithBucket("users").
		WithIndexName("twitter_bin").
		WithIndexKey("jsmith123").
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	printIndexQueryResults(cmd)
	return nil
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:18,代码来源:main.go


示例20: storeUserThenDelete

func storeUserThenDelete(cluster *riak.Cluster) {
	obj := &riak.Object{
		ContentType:     "application/json",
		Charset:         "utf-8",
		ContentEncoding: "utf-8",
		Value:           []byte("{'user':'data'}"),
	}

	cmd, err := riak.NewStoreValueCommandBuilder().
		WithBucketType("users").
		WithBucket("random_user_keys").
		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.Printf("Generated key: %v\n", rsp.GeneratedKey)

	cmd, err = riak.NewDeleteValueCommandBuilder().
		WithBucketType("users").
		WithBucket("random_user_keys").
		WithKey(rsp.GeneratedKey).
		Build()

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	if err := cluster.Execute(cmd); err != nil {
		fmt.Println(err.Error())
		return
	}
}
开发者ID:pguelpa,项目名称:riak-go-client,代码行数:44,代码来源:main.go



注:本文中的github.com/basho/riak-go-client.Cluster类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang riak_dt.MapOp类代码示例发布时间:2022-05-24
下一篇:
Golang metadata_manager.ZkNode类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap