本文整理汇总了Golang中github.com/aerospike/aerospike-client-go.Client.Operate方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Operate方法的具体用法?Golang Client.Operate怎么用?Golang Client.Operate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aerospike/aerospike-client-go.Client
的用法示例。
在下文中一共展示了Client.Operate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runExample
func runExample(client *as.Client) {
// Write initial record.
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "opkey")
bin1 := as.NewBin("optintbin", 7)
bin2 := as.NewBin("optstringbin", "string value")
log.Printf("Put: namespace=%s set=%s key=%s bin1=%s value1=%s bin2=%s value2=%s",
key.Namespace(), key.SetName(), key.Value(), bin1.Name, bin1.Value, bin2.Name, bin2.Value)
client.PutBins(shared.WritePolicy, key, bin1, bin2)
// Add integer, write new string and read record.
bin3 := as.NewBin(bin1.Name, 4)
bin4 := as.NewBin(bin2.Name, "new string")
log.Println("Add: ", bin3.Value)
log.Println("Write: ", bin4.Value)
log.Println("Read:")
record, err := client.Operate(shared.WritePolicy, key, as.AddOp(bin3), as.PutOp(bin4), as.GetOp())
shared.PanicOnError(err)
if record == nil {
log.Fatalf(
"Failed to get: namespace=%s set=%s key=%s",
key.Namespace(), key.SetName(), key.Value())
}
binExpected := as.NewBin(bin3.Name, 11)
shared.ValidateBin(key, binExpected, record)
shared.ValidateBin(key, bin4, record)
}
示例2: 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)
}
}
示例3: runExample
func runExample(client *as.Client) {
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "touchkey")
bin := as.NewBin("touchbin", "touchvalue")
log.Printf("Create record with 2 second expiration.")
writePolicy := as.NewWritePolicy(0, 2)
client.PutBins(writePolicy, key, bin)
log.Printf("Touch same record with 5 second expiration.")
writePolicy.Expiration = 5
record, err := client.Operate(writePolicy, key, as.TouchOp(), as.GetHeaderOp())
if record == nil {
log.Fatalf(
"Failed to get: namespace=%s set=%s key=%s bin=%s value=%s",
key.Namespace(), key.SetName(), key.Value(), bin.Name, nil)
}
if record.Expiration == 0 {
log.Fatalf(
"Failed to get record expiration: namespace=%s set=%s key=%s",
key.Namespace(), key.SetName(), key.Value())
}
log.Printf("Sleep 3 seconds.")
time.Sleep(3 * time.Second)
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())
}
log.Printf("Success. Record still exists.")
log.Printf("Sleep 4 seconds.")
time.Sleep(4 * time.Second)
record, err = client.Get(shared.Policy, key, bin.Name)
shared.PanicOnError(err)
if record == nil {
log.Printf("Success. Record expired as expected.")
} else {
log.Fatalf("Found record when it should have expired.")
}
}
示例4: NewServiceCodeVersion
// NewServiceCodeVersion generates a version number of the code and returns it.
func NewServiceCodeVersion(
as *aerospike.Client, env string, service string) (
newVersion int64, err error) {
key, err := serviceKey(env, service)
if err != nil {
return 0, err
}
bin := aerospike.NewBin("NextVer", 1)
record, err := as.Operate(
nil, key, aerospike.AddOp(bin),
aerospike.GetOpForBin("NextVer"))
if err != nil {
return 0, err
}
return int64(record.Bins["NextVer"].(int)), nil
}