示例#1
0
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))
}
示例#2
0
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
}
示例#3
0
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
0
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", "*****@*****.**")

	cmd, err := riak.NewStoreValueCommandBuilder().
		WithContent(obj).
		Build()
	if err != nil {
		return err
	}

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

	return nil
}
示例#5
0
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
0
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)
}
示例#7
0
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")
}
示例#8
0
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)
}
示例#9
0
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)
}
示例#10
0
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
	}
}
func (dao *LogRecordRiakDao) SaveLogRecord(logId string, logRecord string) error {
	value := &riak.Object{
		ContentType:     "text/plain",
		Charset:         "utf-8",
		ContentEncoding: "utf-8",
		Value:           []byte(logRecord),
	}

	cmd, _ := riak.NewStoreValueCommandBuilder().
		WithKey(logId).
		WithBucket(dao.LogBucket).
		WithContent(value).
		Build()
	return dao.Cluster.Execute(cmd)
}
示例#12
0
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
}
func (dao *LogIndexRiakDAO) store(userId string, value riak.Object) error {
	cmd, err := riak.NewStoreValueCommandBuilder().
		WithBucket(dao.IndexBucket).
		WithKey(userId).
		WithContent(&value).
		Build()
	if err != nil {
		logErr("Saving timeline index for "+userId, err)
		return err
	}
	if err = dao.Cluster.Execute(cmd); err != nil {
		logErr("Saving timeline index for "+userId, err)
		return err
	}
	return nil
}
示例#14
0
func storeUserThenDelete(cluster *riak.Cluster) {
	obj := &riak.Object{
		ContentType:     "application/json",
		Charset:         "utf-8",
		ContentEncoding: "utf-8",
		Value:           []byte("{'user':'******'}"),
	}

	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
	}
}
示例#15
0
func updateCoach(cluster *riak.Cluster, team, newCoach string) error {
	var cmd riak.Command
	var err error

	cmd, err = riak.NewFetchValueCommandBuilder().
		WithBucketType("siblings").
		WithBucket("coaches").
		WithKey(team).
		Build()

	if err != nil {
		return err
	}

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

	fvc := cmd.(*riak.FetchValueCommand)
	obj := fvc.Response.Values[0]
	obj.Value = []byte(newCoach)

	cmd, err = riak.NewStoreValueCommandBuilder().
		WithBucketType("siblings").
		WithBucket("coaches").
		WithKey(team).
		WithContent(obj).
		Build()

	if err != nil {
		return err
	}

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

	return nil
}
示例#16
0
func main() {
	var err error
	var customerId string

	util.Log.Println("Creating Data")

	var cd time.Time
	cd, err = time.Parse(timeFmt, "2013-10-01 14:30:26")
	if err != nil {
		util.ErrExit(err)
	}

	customer := &Customer{
		Name:        "John Smith",
		Address:     "123 Main Street",
		City:        "Columbus",
		State:       "Ohio",
		Zip:         "43210",
		Phone:       "+1-614-555-5555",
		CreatedDate: cd,
	}

	util.Log.Printf("customer: %v", customer)

	util.Log.Println("Starting Client")

	// un-comment-out to enable debug logging
	// riak.EnableDebugLogging = true

	o := &riak.NewClientOptions{
		RemoteAddresses: []string{util.GetRiakAddress()},
	}

	var c *riak.Client
	c, err = riak.NewClient(o)
	if err != nil {
		util.ErrExit(err)
	}

	defer func() {
		if err := c.Stop(); err != nil {
			util.ErrExit(err)
		}
	}()

	util.Log.Println("Storing Customer")

	var cmd riak.Command
	var customerJson []byte

	customerJson, err = json.Marshal(customer)
	if err != nil {
		util.ErrExit(err)
	}

	obj := &riak.Object{
		Bucket:      customersBucket,
		ContentType: "application/json",
		Value:       customerJson,
	}

	cmd, err = riak.NewStoreValueCommandBuilder().
		WithContent(obj).
		WithReturnBody(true).
		Build()
	if err != nil {
		util.ErrExit(err)
	}
	if eerr := c.Execute(cmd); eerr != nil {
		util.ErrExit(eerr)
	}

	svc := cmd.(*riak.StoreValueCommand)
	customerId = svc.Response.GeneratedKey
	if customerId == "" {
		util.ErrExit(errors.New("expected generated customer Id"))
	} else {
		util.Log.Println("Customer ID:", customerId)
	}

	util.Log.Println("Storing Data")

	var orders []*Order
	orders, err = createOrders(customerId)
	if err != nil {
		util.ErrExit(err)
	}

	var orderSummary *OrderSummary
	var orderSummaryJson []byte
	orderSummary = createOrderSummary(customerId, orders)

	ccmds := 1 + len(orders)
	cmds := make([]riak.Command, ccmds)

	// command to store OrderSummary
	orderSummaryJson, err = json.Marshal(orderSummary)
	if err != nil {
		util.ErrExit(err)
	}
	obj = &riak.Object{
		Bucket:      orderSummariesBucket,
		Key:         customerId,
		ContentType: "application/json",
		Value:       orderSummaryJson,
	}
	cmds[0], err = riak.NewStoreValueCommandBuilder().
		WithContent(obj).
		Build()
	if err != nil {
		util.ErrExit(err)
	}

	for i, order := range orders {
		// command to store Order
		var orderJson []byte
		orderJson, err = json.Marshal(order)
		if err != nil {
			util.ErrExit(err)
		}
		obj = &riak.Object{
			Bucket:      ordersBucket,
			Key:         order.Id,
			ContentType: "application/json",
			Value:       orderJson,
		}
		cmds[i+1], err = riak.NewStoreValueCommandBuilder().
			WithContent(obj).
			Build()
		if err != nil {
			util.ErrExit(err)
		}
	}

	errored := false
	wg := &sync.WaitGroup{}
	for _, cmd := range cmds {
		a := &riak.Async{
			Command: cmd,
			Wait:    wg,
		}
		if eerr := c.ExecuteAsync(a); eerr != nil {
			errored = true
			util.ErrLog.Println(eerr)
		}
	}
	wg.Wait()
	if errored {
		util.ErrExit(errors.New("error, exiting!"))
	}

	util.Log.Println("Fetching related data by shared key")

	cmds = cmds[:0]

	// fetch customer
	cmd, err = riak.NewFetchValueCommandBuilder().
		WithBucket(customersBucket).
		WithKey(customerId).
		Build()
	if err != nil {
		util.ErrExit(err)
	}
	cmds = append(cmds, cmd)

	// fetch OrderSummary
	cmd, err = riak.NewFetchValueCommandBuilder().
		WithBucket(orderSummariesBucket).
		WithKey(customerId).
		Build()
	if err != nil {
		util.ErrExit(err)
	}
	cmds = append(cmds, cmd)

	doneChan := make(chan riak.Command)
	errored = false
	for _, cmd := range cmds {
		a := &riak.Async{
			Command: cmd,
			Done:    doneChan,
		}
		if eerr := c.ExecuteAsync(a); eerr != nil {
			errored = true
			util.ErrLog.Println(eerr)
		}
	}
	if errored {
		util.ErrExit(errors.New("error, exiting!"))
	}

	for i := 0; i < len(cmds); i++ {
		select {
		case d := <-doneChan:
			if fv, ok := d.(*riak.FetchValueCommand); ok {
				obj := fv.Response.Values[0]
				switch obj.Bucket {
				case customersBucket:
					util.Log.Printf("Customer     1: %v", string(obj.Value))
				case orderSummariesBucket:
					util.Log.Printf("OrderSummary 1: %v", string(obj.Value))
				}
			} else {
				util.ErrExit(fmt.Errorf("unknown response command type: %v", reflect.TypeOf(d)))
			}
		case <-time.After(5 * time.Second):
			util.ErrExit(errors.New("fetch operations took too long"))
		}
	}

	util.Log.Println("Adding Index Data")

	// fetch orders to add index data
	cmds = cmds[:0]

	for _, order := range orders {
		cmd, err = riak.NewFetchValueCommandBuilder().
			WithBucket(ordersBucket).
			WithKey(order.Id).
			Build()
		if err != nil {
			util.ErrExit(err)
		}
		cmds = append(cmds, cmd)
	}

	errored = false
	for _, cmd := range cmds {
		a := &riak.Async{
			Command: cmd,
			Done:    doneChan,
		}
		if eerr := c.ExecuteAsync(a); eerr != nil {
			errored = true
			util.ErrLog.Println(eerr)
		}
	}
	if errored {
		util.ErrExit(errors.New("error, exiting!"))
	}

	errored = false
	for i := 0; i < len(cmds); i++ {
		select {
		case d := <-doneChan:
			if fv, ok := d.(*riak.FetchValueCommand); ok {
				obj := fv.Response.Values[0]
				switch obj.Key {
				case "1":
					obj.AddToIntIndex("SalespersonId_int", 9000)
					obj.AddToIndex("OrderDate_bin", "2013-10-01")
				case "2":
					obj.AddToIntIndex("SalespersonId_int", 9001)
					obj.AddToIndex("OrderDate_bin", "2013-10-15")
				case "3":
					obj.AddToIntIndex("SalespersonId_int", 9000)
					obj.AddToIndex("OrderDate_bin", "2013-11-03")
				}
				scmd, serr := riak.NewStoreValueCommandBuilder().
					WithContent(obj).
					Build()
				if serr != nil {
					util.ErrExit(serr)
				}
				a := &riak.Async{
					Command: scmd,
					Wait:    wg,
				}
				if eerr := c.ExecuteAsync(a); eerr != nil {
					errored = true
					util.ErrLog.Println(eerr)
				}
			} else {
				util.ErrExit(fmt.Errorf("unknown response command type: %v", reflect.TypeOf(d)))
			}
		case <-time.After(5 * time.Second):
			util.ErrExit(errors.New("fetch operations took too long"))
		}
	}

	if errored {
		util.ErrExit(errors.New("error, exiting!"))
	}

	wg.Wait()
	close(doneChan)

	util.Log.Println("Index Queries")

	cmd, err = riak.NewSecondaryIndexQueryCommandBuilder().
		WithBucket(ordersBucket).
		WithIndexName("SalespersonId_int").
		WithIndexKey("9000").
		Build()
	if err != nil {
		util.ErrExit(err)
	}

	if eerr := c.Execute(cmd); eerr != nil {
		util.ErrExit(eerr)
	}

	qcmd := cmd.(*riak.SecondaryIndexQueryCommand)
	for _, rslt := range qcmd.Response.Results {
		util.Log.Println("Jane's Orders, key: ", string(rslt.ObjectKey))
	}

	cmd, err = riak.NewSecondaryIndexQueryCommandBuilder().
		WithBucket(ordersBucket).
		WithIndexName("OrderDate_bin").
		WithRange("2013-10-01", "2013-10-31").
		Build()
	if err != nil {
		util.ErrExit(err)
	}

	if eerr := c.Execute(cmd); eerr != nil {
		util.ErrExit(eerr)
	}

	qcmd = cmd.(*riak.SecondaryIndexQueryCommand)
	for _, rslt := range qcmd.Response.Results {
		util.Log.Println("October's Orders, key: ", string(rslt.ObjectKey))
	}
}
示例#17
0
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
}
示例#18
0
func main() {
	var err error

	// un-comment-out to enable debug logging
	// riak.EnableDebugLogging = true

	o := &riak.NewClientOptions{
		RemoteAddresses: []string{util.GetRiakAddress()},
	}

	var c *riak.Client
	c, err = riak.NewClient(o)
	if err != nil {
		util.ErrExit(err)
	}

	defer func() {
		if err := c.Stop(); err != nil {
			util.ErrExit(err)
		}
	}()

	val1 := uint32(1)
	val1buf := make([]byte, 4)
	binary.LittleEndian.PutUint32(val1buf, val1)

	val2 := "two"

	val3 := struct{ MyValue int }{3} // NB: ensure that members are exported (i.e. capitalized)
	var val3json []byte
	val3json, err = json.Marshal(val3)
	if err != nil {
		util.ErrExit(err)
	}

	bucket := "test"

	util.Log.Println("Creating Objects In Riak...")

	objs := []*riak.Object{
		{
			Bucket:      bucket,
			Key:         "one",
			ContentType: "application/octet-stream",
			Value:       val1buf,
		},
		{
			Bucket:      bucket,
			Key:         "two",
			ContentType: "text/plain",
			Value:       []byte(val2),
		},
		{
			Bucket:      bucket,
			Key:         "three",
			ContentType: "application/json",
			Value:       val3json,
		},
	}

	var cmd riak.Command
	wg := &sync.WaitGroup{}

	for _, o := range objs {
		cmd, err = riak.NewStoreValueCommandBuilder().
			WithContent(o).
			Build()
		if err != nil {
			util.ErrLog.Println(err)
			continue
		}
		a := &riak.Async{
			Command: cmd,
			Wait:    wg,
		}
		if err := c.ExecuteAsync(a); err != nil {
			util.ErrLog.Println(err)
		}
	}

	wg.Wait()

	util.Log.Println("Reading Objects From Riak...")

	d := make(chan riak.Command, len(objs))

	for _, o := range objs {
		cmd, err = riak.NewFetchValueCommandBuilder().
			WithBucket(bucket).
			WithKey(o.Key).
			Build()
		if err != nil {
			util.ErrLog.Println(err)
			continue
		}
		a := &riak.Async{
			Command: cmd,
			Wait:    wg,
			Done:    d,
		}
		if err := c.ExecuteAsync(a); err != nil {
			util.ErrLog.Println(err)
		}
	}

	wg.Wait()
	close(d)

	var obj3 *riak.Object

	for done := range d {
		f := done.(*riak.FetchValueCommand)
		/* un-comment to dump fetched object as JSON
		if json, jerr := json.MarshalIndent(f.Response, "", "  "); err != nil {
			util.ErrLog.Println(jerr)
		} else {
			util.Log.Println("fetched value: ", string(json))
		}
		*/
		obj := f.Response.Values[0]
		switch obj.Key {
		case "one":
			if actual, expected := binary.LittleEndian.Uint32(obj.Value), val1; actual != expected {
				util.ErrLog.Printf("key: %s, actual %v, expected %v", obj.Key, actual, expected)
			}
		case "two":
			if actual, expected := string(obj.Value), val2; actual != expected {
				util.ErrLog.Printf("key: %s, actual %v, expected %v", obj.Key, actual, expected)
			}
		case "three":
			obj3 = obj
			val3.MyValue = 0
			if jerr := json.Unmarshal(obj.Value, &val3); jerr != nil {
				util.ErrLog.Println(jerr)
			} else {
				if actual, expected := val3.MyValue, int(3); actual != expected {
					util.ErrLog.Printf("key: %s, actual %v, expected %v", obj.Key, actual, expected)
				}
			}
		default:
			util.ErrLog.Printf("unrecognized key: %s", obj.Key)
		}
	}

	util.Log.Println("Updating Object Three In Riak...")

	val3.MyValue = 42
	obj3.Value, err = json.Marshal(val3)
	if err != nil {
		util.ErrExit(err)
	}

	cmd, err = riak.NewStoreValueCommandBuilder().
		WithContent(obj3).
		WithReturnBody(true).
		Build()
	if err != nil {
		util.ErrLog.Println(err)
	} else {
		if err := c.Execute(cmd); err != nil {
			util.ErrLog.Println(err)
		}
	}

	svcmd := cmd.(*riak.StoreValueCommand)
	svrsp := svcmd.Response
	obj3 = svrsp.Values[0]
	val3.MyValue = 0
	if jerr := json.Unmarshal(obj3.Value, &val3); jerr != nil {
		util.ErrLog.Println(jerr)
	} else {
		if actual, expected := val3.MyValue, int(42); actual != expected {
			util.ErrLog.Printf("key: %s, actual %v, expected %v", obj3.Key, actual, expected)
		}
	}
	util.Log.Println("updated object key: ", obj3.Key)
	util.Log.Println("updated object value: ", val3.MyValue)

	book := &Book{
		ISBN:        "1111979723",
		Title:       "Moby Dick",
		Author:      "Herman Melville",
		Body:        "Call me Ishmael. Some years ago...",
		CopiesOwned: 3,
	}

	var jbook []byte
	jbook, err = json.Marshal(book)
	if err != nil {
		util.ErrExit(err)
	}

	bookObj := &riak.Object{
		Bucket:      "books",
		Key:         book.ISBN,
		ContentType: "application/json",
		Value:       jbook,
	}

	cmd, err = riak.NewStoreValueCommandBuilder().
		WithContent(bookObj).
		WithReturnBody(false).
		Build()
	if err != nil {
		util.ErrLog.Println(err)
	} else {
		if err := c.Execute(cmd); err != nil {
			util.ErrLog.Println(err)
		}
	}

	cmd, err = riak.NewFetchValueCommandBuilder().
		WithBucket("books").
		WithKey(book.ISBN).
		Build()
	if err != nil {
		util.ErrExit(err)
	}
	if err := c.Execute(cmd); err != nil {
		util.ErrLog.Println(err)
	}

	fcmd := cmd.(*riak.FetchValueCommand)
	bookObj = fcmd.Response.Values[0]
	util.Log.Println("serialized object: ", string(bookObj.Value))

	util.Log.Println("Deleting Objects From Riak...")

	objs = append(objs, bookObj)
	for _, o := range objs {
		cmd, err = riak.NewDeleteValueCommandBuilder().
			WithBucket(o.Bucket).
			WithKey(o.Key).
			Build()
		if err != nil {
			util.ErrLog.Println(err)
			continue
		}
		a := &riak.Async{
			Command: cmd,
			Wait:    wg,
		}
		if err := c.ExecuteAsync(a); err != nil {
			util.ErrLog.Println(err)
		}
	}

	wg.Wait()
}