Aerospike Golang多主机示例?

huangapple go评论81阅读模式
英文:

Aerospike Golang Multi Host example?

问题

我想使用Golang Aerospike与4个本地服务器进行连接,我可以使用以下PHP代码进行连接:

// AEROSPIKE连接配置
hosts := []*aerospike.Host{
    {Addr: "192.168.7.241", Port: 3000},
    {Addr: "192.168.7.243", Port: 3000},
    {Addr: "192.168.7.244", Port: 3000},
    {Addr: "192.168.7.245", Port: 3000},
}

// 创建AEROSPIKE客户端
client, err := aerospike.NewClientWithPolicyAndHost(nil, hosts...)
if err != nil {
    log.Fatalf("Failed to connect to Aerospike: %v", err)
}
defer client.Close()

你可以使用这个链接https://github.com/aerospike/aerospike-client-go中的aerospike-client-go库来实现。在该库中,你可以使用NewClientWithPolicyAndHost函数和NewHosts函数来创建Aerospike客户端。以上是一个示例代码,你可以根据自己的需求进行修改。

请注意,你需要确保已经安装了aerospike-client-go库,并且你的Go版本是1.17。

英文:

i want to use golang aerospike with 4 server local , i can connect this using PHP code like this

#CONFIG FOR AEROSPIKE CONNECTION
	$CONF['aerospike_server'] = array(
		'hosts' => array(
			array(
				'addr' => '192.168.7.241',
				'port' => 3000
			),
			array(
				'addr' => '192.168.7.243',
				'port' => 3000
			),
			array(
				'addr' => '192.168.7.244',
				'port' => 3000
			),
			array(
				'addr' => '192.168.7.245',
				'port' => 3000
			)
		)
	);


$aeroDB = new Aerospike($CONF['aerospike_server']);

how do i do this using golang ? im using this https://github.com/aerospike/aerospike-client-go
also i read in reference does have NewClientWithPolicyAndHost and NewHosts but cannot find the example or how to use it.

i am using go version go1.17 linux/amd64

答案1

得分: 4

我成功获取了一些输入,假设我正确理解了问题:

client, err := aero.NewClientWithPolicyAndHost(aero.NewClientPolicy(), aero.NewHost(ip1, port1), aero.NewHost(ip2, port2), aero.NewHost(ip3, port3), aero.NewHost(ip4, port4))
if err != nil {
    log.Fatal(err)
}

这段代码创建了一个 Aerospike 客户端对象 client,并使用了一些主机地址进行初始化。如果初始化过程中出现错误,会打印错误信息并终止程序。

英文:

I did manage to get some input, assuming I understood the question right:

client, err := aero.NewClientWithPolicyAndHost(aero.NewClientPolicy(), aero.NewHost(ip1, port1), aero.NewHost(ip2, port2), aero.NewHost(ip3, port3), aero.NewHost(ip4, port4))
if err != nil {
    log.Fatal(err)
}

huangapple
  • 本文由 发表于 2022年4月4日 16:57:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/71734477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定