当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Delete方法代码示例

本文整理汇总了Golang中github.com/archsaber/aerospike-client-go.Client.Delete方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Delete方法的具体用法?Golang Client.Delete怎么用?Golang Client.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/archsaber/aerospike-client-go.Client的用法示例。


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

示例1: runExample

func runExample(client *as.Client) {
	key, err := as.NewKey(*shared.Namespace, *shared.Set, "addkey")
	shared.PanicOnError(err)

	binName := "addbin"

	// Delete record if it already exists.
	client.Delete(shared.WritePolicy, key)

	// Perform some adds and check results.
	bin := as.NewBin(binName, 10)
	log.Println("Initial add will create record.  Initial value is ", bin.Value, ".")
	client.AddBins(shared.WritePolicy, key, bin)

	bin = as.NewBin(binName, 5)
	log.Println("Add ", bin.Value, " to existing record.")
	client.AddBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)

	if record == nil {
		log.Fatalf(
			"Failed to get: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	// The value received from the server is an unsigned byte stream.
	// Convert to an integer before comparing with expected.
	received := record.Bins[bin.Name]
	expected := 15

	if received == expected {
		log.Printf("Add successful: ns=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Add mismatch: Expected %d. Received %d.", expected, received)
	}

	// Demonstrate add and get combined.
	bin = as.NewBin(binName, 30)
	log.Println("Add ", bin.Value, " to existing record.")
	record, err = client.Operate(shared.WritePolicy, key, as.AddOp(bin), as.GetOp())
	shared.PanicOnError(err)

	expected = 45
	received = record.Bins[bin.Name]

	if received == expected {
		log.Printf("Add successful: ns=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Add mismatch: Expected %d. Received %d.", expected, received)
	}
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:55,代码来源:add.go

示例2: testListMapCombined

/**
 * Write/Read Array/Map combination directly instead of relying on java serializer.
 */
func testListMapCombined(client *as.Client) {
	log.Printf("Read/Write Array/Map")
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "listmapkey")
	client.Delete(shared.WritePolicy, key)

	blob := []byte{3, 52, 125}
	inner := []interface{}{
		"string2",
		5,
	}

	innerMap := map[interface{}]interface{}{
		"a":    1,
		2:      "b",
		3:      blob,
		"list": inner,
	}

	list := []interface{}{
		"string1",
		8,
		inner,
		innerMap,
	}

	bin := as.NewBin("listmapbin", list)
	client.PutBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	received := record.Bins[bin.Name].([]interface{})

	validateSize(4, len(received))
	validate("string1", received[0])
	// Server convert numbers to long, so must expect long.
	validate(8, received[1])

	receivedInner := received[2].([]interface{})
	validateSize(2, len(receivedInner))
	validate("string2", receivedInner[0])
	validate(5, receivedInner[1])

	receivedMap := received[3].(map[interface{}]interface{})
	validateSize(4, len(receivedMap))
	validate(1, receivedMap["a"])
	validate("b", receivedMap[2])
	validateBytes(blob, receivedMap[3].([]byte))

	receivedInner2 := receivedMap["list"].([]interface{})
	validateSize(2, len(receivedInner2))
	validate("string2", receivedInner2[0])
	validate(5, receivedInner2[1])

	log.Printf("Read/Write Array/Map successful")
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:58,代码来源:list_map.go

示例3: testMapComplex

/**
 * Write/Read map[interface{}]interface{} directly instead of relying on java serializer.
 */
func testMapComplex(client *as.Client) {
	log.Printf("Read/Write map[interface{}]interface{}")
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "mapkey2")
	client.Delete(shared.WritePolicy, key)

	blob := []byte{3, 52, 125}
	list := []int{
		100034,
		12384955,
		3,
		512,
	}

	amap := map[interface{}]interface{}{
		"key1": "string1",
		"key2": 2,
		"key3": blob,
		"key4": list,
	}

	bin := as.NewBin("mapbin2", amap)
	client.PutBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	receivedMap := record.Bins[bin.Name].(map[interface{}]interface{})

	validateSize(4, len(receivedMap))
	validate("string1", receivedMap["key1"])
	// Server convert numbers to long, so must expect long.
	validate(2, receivedMap["key2"])
	validateBytes(blob, receivedMap["key3"].([]byte))

	receivedInner := receivedMap["key4"].([]interface{})
	validateSize(4, len(receivedInner))
	validate(100034, receivedInner[0])
	validate(12384955, receivedInner[1])
	validate(3, receivedInner[2])
	validate(512, receivedInner[3])

	log.Printf("Read/Write map[interface{}]interface{} successful")
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:45,代码来源:list_map.go

示例4: runReplaceOnlyExample

func runReplaceOnlyExample(client *as.Client) {
	key, err := as.NewKey(*shared.Namespace, *shared.Set, "replaceonlykey")
	shared.PanicOnError(err)
	bin := as.NewBin("bin", "value")

	// Delete record if it already exists.
	client.Delete(shared.WritePolicy, key)

	log.Printf("Replace record requiring that it exists: namespace=%s set=%s key=%s",
		key.Namespace(), key.SetName(), key.Value())

	wpolicy := as.NewWritePolicy(0, 0)
	wpolicy.RecordExistsAction = as.REPLACE_ONLY
	err = client.PutBins(wpolicy, key, bin)
	if ae, ok := err.(ast.AerospikeError); ok && ae.ResultCode() == ast.KEY_NOT_FOUND_ERROR {
		log.Printf("Success. `Not found` error returned as expected.")
	} else {
		log.Fatalln("Failure. This command should have resulted in an error.")
	}
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:20,代码来源:replace.go

示例5: testListStrings

/**
 * Write/Read []string directly instead of relying on java serializer.
 */
func testListStrings(client *as.Client) {
	log.Printf("Read/Write []string")
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "listkey1")
	client.Delete(shared.WritePolicy, key)

	list := []string{"string1", "string2", "string3"}

	bin := as.NewBin("listbin1", list)
	client.PutBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	receivedList := record.Bins[bin.Name].([]interface{})

	validateSize(3, len(receivedList))
	validate("string1", receivedList[0])
	validate("string2", receivedList[1])
	validate("string3", receivedList[2])

	log.Printf("Read/Write []string successful.")
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:24,代码来源:list_map.go

示例6: writeIfNotExists

func writeIfNotExists(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "udfkey3")
	binName := "udfbin3"

	// Delete record if it already exists.
	client.Delete(shared.WritePolicy, key)

	// Write record only if not already exists. This should succeed.
	client.Execute(shared.WritePolicy, key, "record_example", "writeUnique", as.NewValue(binName), as.NewValue("first"))

	// Verify record written.
	record, err := client.Get(shared.Policy, key, binName)
	shared.PanicOnError(err)
	expected := "first"
	received := record.Bins[binName].(string)

	if received == expected {
		log.Printf("Record written: namespace=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), binName, received)
	} else {
		log.Printf("Data mismatch: Expected %s. Received %s.", expected, received)
	}

	// Write record second time. This should fail.
	log.Printf("Attempt second write.")
	client.Execute(shared.WritePolicy, key, "record_example", "writeUnique", as.NewValue(binName), as.NewValue("second"))

	// Verify record not written.
	record, err = client.Get(shared.Policy, key, binName)
	shared.PanicOnError(err)
	received = record.Bins[binName].(string)

	if received == expected {
		log.Printf("Success. Record remained unchanged: namespace=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), binName, received)
	} else {
		log.Printf("Data mismatch: Expected %s. Received %s.", expected, received)
	}
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:39,代码来源:udf.go

示例7: runExample

func runExample(client *as.Client) {
	key, err := as.NewKey(*shared.Namespace, *shared.Set, "prependkey")
	shared.PanicOnError(err)

	binName := "prependbin"

	// Delete record if it already exists.
	client.Delete(shared.WritePolicy, key)

	bin := as.NewBin(binName, "World")
	log.Println("Initial prepend will create record.  Initial value is ", bin.Value, ".")
	client.PrependBins(shared.WritePolicy, key, bin)

	bin = as.NewBin(binName, "Hello ")
	log.Println("Prepend \"", bin.Value, "\" to existing record.")
	client.PrependBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)

	if record == nil {
		log.Fatalf(
			"Failed to get: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	// The value received from the server is an unsigned byte stream.
	// Convert to an integer before comparing with expected.
	received := record.Bins[bin.Name]
	expected := "Hello World"

	if received == expected {
		log.Printf("Prepend successful: ns=%s set=%s key=%s bin=%s value=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
	} else {
		log.Fatalf("Prepend mismatch: Expected %s. Received %s.", expected, received)
	}
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:38,代码来源:prepend.go

示例8: testMapStrings

/**
 * Write/Read map[string]string directly instead of relying on java serializer.
 */
func testMapStrings(client *as.Client) {
	log.Printf("Read/Write map[string]string")
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "mapkey1")
	client.Delete(shared.WritePolicy, key)

	amap := map[string]string{"key1": "string1",
		"key2": "string2",
		"key3": "string3",
	}
	bin := as.NewBin("mapbin1", amap)
	client.PutBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	receivedMap := record.Bins[bin.Name].(map[interface{}]interface{})

	validateSize(3, len(receivedMap))
	validate("string1", receivedMap["key1"])
	validate("string2", receivedMap["key2"])
	validate("string3", receivedMap["key3"])

	log.Printf("Read/Write map[string]string successful")
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:26,代码来源:list_map.go

示例9: testListComplex

/**
 * Write/Read []interface{} directly instead of relying on java serializer.
 */
func testListComplex(client *as.Client) {
	log.Printf("Read/Write []interface{}")
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "listkey2")
	client.Delete(shared.WritePolicy, key)

	blob := []byte{3, 52, 125}
	list := []interface{}{"string1", 2, blob}

	bin := as.NewBin("listbin2", list)
	client.PutBins(shared.WritePolicy, key, bin)

	record, err := client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)
	receivedList := record.Bins[bin.Name].([]interface{})

	validateSize(3, len(receivedList))
	validate("string1", receivedList[0])
	// Server convert numbers to long, so must expect long.
	validate(2, receivedList[1])
	validateBytes(blob, receivedList[2].([]byte))

	log.Printf("Read/Write []interface{} successful.")
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:26,代码来源:list_map.go

示例10: runExample

func runExample(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "genkey")
	binName := "genbin"

	// Delete record if it already exists.
	client.Delete(shared.WritePolicy, key)

	// Set some values for the same record.
	bin := as.NewBin(binName, "genvalue1")
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value)

	client.PutBins(shared.WritePolicy, key, bin)

	bin = as.NewBin(binName, "genvalue2")
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value)

	client.PutBins(shared.WritePolicy, key, bin)

	// Retrieve record and its generation count.
	record, err := client.Get(shared.Policy, key, bin.Name)

	if record == nil {
		log.Fatalf(
			"Failed to get: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	received := record.Bins[bin.Name]
	expected := bin.Value.String()

	if received == expected {
		log.Printf("Get successful: namespace=%s set=%s key=%s bin=%s value=%s generation=%d",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received, record.Generation)
	} else {
		log.Fatalf("Get mismatch: Expected %s. Received %s.",
			expected, received)
	}

	// Set record and fail if it's not the expected generation.
	bin = as.NewBin(binName, "genvalue3")
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s expected generation=%d",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value, record.Generation)

	writePolicy := as.NewWritePolicy(0, 2)
	writePolicy.GenerationPolicy = as.EXPECT_GEN_EQUAL
	writePolicy.Generation = record.Generation
	client.PutBins(writePolicy, key, bin)

	// Set record with invalid generation and check results .
	bin = as.NewBin(binName, "genvalue4")
	writePolicy.Generation = 9999
	log.Printf("Put: namespace=%s set=%s key=%s bin=%s value=%s expected generation=%d",
		key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value, writePolicy.Generation)

	err = client.PutBins(writePolicy, key, bin)
	if err != nil {
		if ae, ok := err.(ast.AerospikeError); ok && ae.ResultCode() == ast.GENERATION_ERROR {
			shared.PanicOnError(errors.New("Should have received generation error instead of success."))
		}
		log.Printf("Success: Generation error returned as expected.")
	} else {
		log.Fatalf(
			"Unexpected set return code: namespace=%s set=%s key=%s bin=%s value=%s code=%s",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, bin.Value, err)
	}

	// Verify results.
	record, err = client.Get(shared.Policy, key, bin.Name)
	shared.PanicOnError(err)

	if record == nil {
		log.Fatalf(
			"Failed to get: namespace=%s set=%s key=%s",
			key.Namespace(), key.SetName(), key.Value())
	}

	received = record.Bins[bin.Name]
	expected = "genvalue3"

	if received == expected {
		log.Printf("Get successful: namespace=%s set=%s key=%s bin=%s value=%s generation=%d",
			key.Namespace(), key.SetName(), key.Value(), bin.Name, received, record.Generation)
	} else {
		log.Fatalf("Get mismatch: Expected %s. Received %s.",
			expected, received)
	}
}
开发者ID:archsaber,项目名称:aerospike-client-go,代码行数:89,代码来源:generation.go


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