Exemplo n.º 1
0
func main() {
	//riak.EnableDebugLogging = true

	nodeOpts := &riak.NodeOptions{
		RemoteAddress: "riak-test:10017",
	}

	var node *riak.Node
	var err error
	if node, err = riak.NewNode(nodeOpts); err != nil {
		fmt.Println(err.Error())
	}

	nodes := []*riak.Node{node}
	opts := &riak.ClusterOptions{
		Nodes: nodes,
	}

	cluster, err := riak.NewCluster(opts)
	if err != nil {
		fmt.Println(err.Error())
	}

	defer func() {
		if err := cluster.Stop(); err != nil {
			fmt.Println(err.Error())
		}
	}()

	if err := cluster.Start(); err != nil {
		fmt.Println(err.Error())
	}

	// ping
	ping := &riak.PingCommand{}
	if err := cluster.Execute(ping); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("ping passed")
	}

	fetchRufus(cluster)
	storeRufus(cluster)
	storeStray(cluster)
	fetchRufusWithR(cluster)
	storeQuote(cluster)
	storeAndUpdateSport(cluster)
	storeCar(cluster)
	storeUserThenDelete(cluster)
	fetchBucketProps(cluster)
}
Exemplo n.º 2
0
func initCluster(options []*riak.NodeOptions) (*riak.Cluster, error) {
	nodes := make([]*riak.Node, 0, len(options))
	for _, nodeOpts := range options {
		if node, err := riak.NewNode(nodeOpts); err == nil {
			nodes = append(nodes, node)
		} else {
			logErr("Error initialising new Riak Node", err)
		}
	}
	opts := &riak.ClusterOptions{
		Nodes: nodes,
	}
	return riak.NewCluster(opts)
}
Exemplo n.º 3
0
/*
    Code samples from:
    http://docs.basho.com/riak/latest/dev/using/updates/

	make sure this bucket-type is created:
	siblings

	riak-admin bucket-type create siblings '{"props":{"allow_mult":true}}'
	riak-admin bucket-type activate siblings
*/
func main() {
	//riak.EnableDebugLogging = true

	nodeOpts := &riak.NodeOptions{
		RemoteAddress: "riak-test:10017",
	}

	var node *riak.Node
	var err error
	if node, err = riak.NewNode(nodeOpts); err != nil {
		fmt.Println(err.Error())
	}

	nodes := []*riak.Node{node}
	opts := &riak.ClusterOptions{
		Nodes: nodes,
	}

	cluster, err := riak.NewCluster(opts)
	if err != nil {
		fmt.Println(err.Error())
	}

	defer func() {
		if err := cluster.Stop(); err != nil {
			fmt.Println(err.Error())
		}
	}()

	if err := cluster.Start(); err != nil {
		fmt.Println(err.Error())
	}

	// ping
	ping := &riak.PingCommand{}
	if err := cluster.Execute(ping); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("ping passed")
	}

	storeCoach(cluster)

	if err := updateCoach(cluster, "seahawks", "Bob Abooey"); err != nil {
		fmt.Println(err.Error())
	}
}
Exemplo n.º 4
0
func main() {
	//riak.EnableDebugLogging = true

	nodeOpts := &riak.NodeOptions{
		RemoteAddress:  "riak-test:10017",
		RequestTimeout: time.Second * 60,
	}

	var node *riak.Node
	var err error
	if node, err = riak.NewNode(nodeOpts); err != nil {
		fmt.Println(err.Error())
	}

	nodes := []*riak.Node{node}
	opts := &riak.ClusterOptions{
		Nodes: nodes,
	}

	cluster, err := riak.NewCluster(opts)
	if err != nil {
		fmt.Println(err.Error())
	}

	defer func() {
		if err := cluster.Stop(); err != nil {
			fmt.Println(err.Error())
		}
	}()

	if err := cluster.Start(); err != nil {
		fmt.Println(err.Error())
	}

	// ping
	ping := &riak.PingCommand{}
	if err := cluster.Execute(ping); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("ping passed")
	}

	if err := storeIndex(cluster); err != nil {
		ErrExit(err)
	}

	if err := storeBucketProperties(cluster); err != nil {
		ErrExit(err)
	}

	if err := storeObjects(cluster); err != nil {
		ErrExit(err)
	}

	time.Sleep(time.Millisecond * 1250)

	if err := doSearchRequest(cluster); err != nil {
		ErrExit(err)
	}

	if err := doAgeSearchRequest(cluster); err != nil {
		ErrExit(err)
	}

	if err := doAndSearchRequest(cluster); err != nil {
		ErrExit(err)
	}

	if err := doPaginatedSearchRequest(cluster); err != nil {
		ErrExit(err)
	}

	if err := deleteIndex(cluster); err != nil {
		ErrExit(err)
	}
}
Exemplo n.º 5
0
func main() {
	riak.EnableDebugLogging = false

	nodeOpts := &riak.NodeOptions{
		RemoteAddress: "riak-test:10017",
	}

	var node *riak.Node
	var err error
	if node, err = riak.NewNode(nodeOpts); err != nil {
		fmt.Println(err.Error())
	}

	nodes := []*riak.Node{node}
	opts := &riak.ClusterOptions{
		Nodes:             nodes,
		ExecutionAttempts: 1,
	}

	cluster, err := riak.NewCluster(opts)
	if err != nil {
		fmt.Println(err.Error())
	}

	defer func() {
		if err := cluster.Stop(); err != nil {
			fmt.Println(err.Error())
		}
	}()

	if err := cluster.Start(); err != nil {
		fmt.Println(err.Error())
	}

	// ping
	ping := &riak.PingCommand{}
	if err := cluster.Execute(ping); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("ping passed")
	}

	if err := insertingObjects(cluster); err != nil {
		ErrExit(err)
	}

	if err := queryingIndexes(cluster); err != nil {
		ErrExit(err)
	}

	if err := indexingObjects(cluster); err != nil {
		ErrExit(err)
	}

	if err := invalidFieldNames(cluster); err != nil {
		ErrExit(err)
	}

	if err := incorrectDataType(cluster); err != nil {
		ErrExit(err)
	}

	if err := queryingExactMatch(cluster); err != nil {
		ErrExit(err)
	}

	if err := queryingRange(cluster); err != nil {
		ErrExit(err)
	}

	if err := queryingRangeWithTerms(cluster); err != nil {
		ErrExit(err)
	}

	if err := queryingPagination(cluster); err != nil {
		ErrExit(err)
	}
}
Exemplo n.º 6
0
func main() {
	//riak.EnableDebugLogging = true

	nodeOpts := &riak.NodeOptions{
		RemoteAddress: "riak-test:10017",
	}

	var node *riak.Node
	var err error
	if node, err = riak.NewNode(nodeOpts); err != nil {
		fmt.Println(err.Error())
	}

	nodes := []*riak.Node{node}
	opts := &riak.ClusterOptions{
		Nodes: nodes,
	}

	cluster, err := riak.NewCluster(opts)
	if err != nil {
		fmt.Println(err.Error())
	}

	defer func() {
		if err := cluster.Stop(); err != nil {
			fmt.Println(err.Error())
		}
	}()

	if err := cluster.Start(); err != nil {
		fmt.Println(err.Error())
	}

	// ping
	ping := &riak.PingCommand{}
	if err := cluster.Execute(ping); err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("ping passed")
	}

	obj := &riak.Object{
		ContentType:     "text/plain",
		Charset:         "utf-8",
		ContentEncoding: "utf-8",
		Value:           []byte("Ren"),
	}

	storeObject(cluster, obj)
	storeObject(cluster, obj)
	readSiblings(cluster)

	resolveViaOverwrite(cluster)
	readSiblings(cluster)

	storeObject(cluster, obj)
	storeObject(cluster, obj)
	readSiblings(cluster)

	resolveChoosingFirst(cluster)
	readSiblings(cluster)

	storeObject(cluster, obj)
	storeObject(cluster, obj)
	readSiblings(cluster)

	resolveUsingResolver(cluster)
	readSiblings(cluster)
}