本文整理汇总了Golang中github.com/aerospike/aerospike-client-go.Client.Execute方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Execute方法的具体用法?Golang Client.Execute怎么用?Golang Client.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aerospike/aerospike-client-go.Client
的用法示例。
在下文中一共展示了Client.Execute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeIfGenerationNotChanged
func writeIfGenerationNotChanged(client *as.Client) {
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "udfkey2")
bin := as.NewBin("udfbin2", "string value")
// Seed record.
client.PutBins(shared.WritePolicy, key, bin)
// Get record generation.
gen, err := client.Execute(shared.WritePolicy, key, "record_example", "getGeneration")
shared.PanicOnError(err)
// Write record if generation has not changed.
client.Execute(shared.WritePolicy, key, "record_example", "writeIfGenerationNotChanged", as.NewValue(bin.Name), bin.Value, as.NewValue(gen))
log.Printf("Record written.")
}
示例2: writeUsingUdf
func writeUsingUdf(client *as.Client) {
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "udfkey1")
bin := as.NewBin("udfbin1", "string value")
client.Execute(shared.WritePolicy, key, "record_example", "writeBin", as.NewValue(bin.Name), bin.Value)
record, err := client.Get(shared.Policy, key, bin.Name)
shared.PanicOnError(err)
expected := bin.Value.String()
received := record.Bins[bin.Name].(string)
if received == expected {
log.Printf("Data matched: namespace=%s set=%s key=%s bin=%s value=%s",
key.Namespace(), key.SetName(), key.Value(), bin.Name, received)
} else {
log.Printf("Data mismatch: Expected %s. Received %s.", expected, received)
}
}
示例3: writeWithValidation
func writeWithValidation(client *as.Client) {
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "udfkey4")
binName := "udfbin4"
// Lua function writeWithValidation accepts number between 1 and 10.
// Write record with valid value.
log.Printf("Write with valid value.")
client.Execute(shared.WritePolicy, key, "record_example", "writeWithValidation", as.NewValue(binName), as.NewValue(4))
// Write record with invalid value.
log.Printf("Write with invalid value.")
_, err := client.Execute(shared.WritePolicy, key, "record_example", "writeWithValidation", as.NewValue(binName), as.NewValue(11))
if err == nil {
log.Printf("UDF should not have succeeded!")
} else {
log.Printf("Success. UDF resulted in exception as expected.")
}
}
示例4: writeBlobUsingUdf
func writeBlobUsingUdf(client *as.Client) {
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "udfkey6")
binName := "udfbin6"
// Create packed blob using standard java tools.
dos := bytes.Buffer{}
// dos.Write(9845)
dos.WriteString("Hello world.")
blob := dos.Bytes()
client.Execute(shared.WritePolicy, key, "record_example", "writeBin", as.NewValue(binName), as.NewValue(blob))
received, err := client.Execute(shared.WritePolicy, key, "record_example", "readBin", as.NewValue(binName))
shared.PanicOnError(err)
if bytes.Equal(blob, received.([]byte)) {
log.Printf("Blob data matched: namespace=%s set=%s key=%s bin=%v value=%v",
key.Namespace(), key.SetName(), key.Value(), binName, received)
} else {
log.Fatalf(
"Mismatch: expected=%v received=%v", blob, received)
}
}
示例5: 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)
}
}
示例6: writeListMapUsingUdf
func writeListMapUsingUdf(client *as.Client) {
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "udfkey5")
inner := []interface{}{"string2", int64(8)}
innerMap := map[interface{}]interface{}{"a": int64(1), int64(2): "b", "list": inner}
list := []interface{}{"string1", int64(4), inner, innerMap}
binName := "udfbin5"
client.Execute(shared.WritePolicy, key, "record_example", "writeBin", as.NewValue(binName), as.NewValue(list))
received, err := client.Execute(shared.WritePolicy, key, "record_example", "readBin", as.NewValue(binName))
shared.PanicOnError(err)
if testEq(received.([]interface{}), list) {
log.Printf("UDF data matched: namespace=%s set=%s key=%s bin=%s value=%s",
key.Namespace(), key.SetName(), key.Value(), binName, received)
} else {
log.Println("UDF data mismatch")
log.Println("Expected ", list)
log.Println("Received ", received)
}
}