我正在嘗試使用 golang 使用 PK 記錄,默認(rèn)策略阻止 PK 顯示,因此我需要使用策略 POLICY_KEY_SEND。我可以使用 PHP 制定此政策,但我不知道如何在 golang aerospike 庫(kù)中使用它,這是我的代碼(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貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試添加:
writePolicy.SendKey = true
打電話前:
err = client.Put(writePolicy, key, bins)
根據(jù) Aerospike Go 客戶端文檔:SendKey 選項(xiàng)是BasePolicy
(默認(rèn)為 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 關(guān)注
- 82 瀏覽
添加回答
舉報(bào)
0/150
提交
取消