我正在尝试使用 golang 使用 PK 记录,默认策略阻止 PK 显示,因此我需要使用策略 POLICY_KEY_SEND。我可以使用 PHP 制定此政策,但我不知道如何在 golang aerospike 库中使用它,这是我的代码(Aerospike 和 PHP)Golang(不知道如何放置策略 POLICY_KEY_SEND)package mainimport "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";}
1 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
尝试添加:
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
- 1 回答
- 0 关注
- 63 浏览
添加回答
举报
0/150
提交
取消