gpt4 book ai didi

php - Aerospike Golang 如何使用 POLICY_KEY_SEND?

转载 作者:行者123 更新时间:2023-12-05 02:30:31 24 4
gpt4 key购买 nike

我正在尝试使用 golang 使用 PK 记录,默认策略阻止 PK 显示,因此我需要使用策略 POLICY_KEY_SEND。我可以使用 PHP 制定此政策,但我不知道如何在 golang aerospike 库中使用它,这是我的代码(Aerospike 和 PHP)

Golang(不知道如何放置策略 POLICY_KEY_SEND)

package main

import "fmt"
import aero "github.com/aerospike/aerospike-client-go"

func main() {

client, err := aero.NewClientWithPolicyAndHost(aero.NewClientPolicy(),
aero.NewHost("192.168.7.241", 3000),
aero.NewHost("192.168.7.243", 3000),
aero.NewHost("192.168.7.244", 3000),
aero.NewHost("192.168.7.245", 3000),
)

if err != nil {
fmt.Println("AEROSPIKE CON ERR :",nil)
} else {
fmt.Println("SUCCESS AEROSPIKE")

namespace := "test"
setName := "test_golang_set"

key,err := aero.NewKey(namespace,setName,"ASDF1234")
if err != nil {
fmt.Println("AEROSPIKE KEY ERR :",nil)
} else {
// define some bins
bins := aero.BinMap{
"game" : "P4", // you can pass any supported type as bin value
"genre" : "RPG",
"price" : 59.9,
}

writePolicy := aero.NewWritePolicy(0, 0)
err = client.Put(writePolicy, key, bins)

if err != nil {
fmt.Println("AEROSPIKE PUT ERR :",nil)
} else {
fmt.Println("AEROSPIKE PUT SUCCESS")
}
}
}
}

PHP(使用 POLICY_KEY_SEND)

<?php

/*blablah connection stuff*/

$name_space = "test";
$sets = "test_golang_set";
$pk_sets = "HIJK4869";
$key = $aeroDB->initKey($name_space,$sets,$pk_sets);

$option = [
Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND
];

$bins = [
'game' => 'ELDEN RING',
'genre' => 'Relaxing',
'price' => 59.9
];

$putStatus = $aeroDB->put($key,$bins,0,$option);

if($putStatus == Aerospike::OK) {
echo "OK";
} else {
echo "ERR";
}

这是结果示例,Golang 生成的最后两条记录(PK 未显示,因为未使用 POLICY_KEY_SEND),PHP 的第一条记录(显示 PK,因为 POLICY_KEY_SEND):

aql> select * from test.test_golang_set
+------------+--------------+------------+-------+
| PK | game | genre | price |
+------------+--------------+------------+-------+
| "HIJK4869" | "ELDEN RING" | "Relaxing" | 59.9 |
| | "P5" | "RPG" | 59.9 |
| | "P4" | "RPG" | 59.9 |
+------------+--------------+------------+-------+
3 rows in set (0.508 secs)

ps:我正在使用这个 golang aerospike:https://github.com/aerospike/aerospike-client-go

最佳答案

尝试添加:

writePolicy.SendKey = true

调用前:

err = client.Put(writePolicy, key, bins)

根据 Aerospike Go 客户端文档:SendKey 选项是 BasePolicy 的一部分(默认为 SendKey = false),它是 WritePolicy 的基本策略。

https://pkg.go.dev/github.com/aerospike/aerospike-client-go#BasePolicy https://pkg.go.dev/github.com/aerospike/aerospike-client-go#WritePolicy

关于php - Aerospike Golang 如何使用 POLICY_KEY_SEND?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71824413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com