我遇到了一些奇怪的行为。我正在尝试设置一个小型网络应用程序,该应用程序使用在 Ubuntu 12.04 服务器上运行的 Aerospike 3.5 Community 获取一些数据。我正在使用默认的 aerospike.conf 文件(使用“测试”命名空间),并遵循如何查询 here 的示例。 .
当我尝试使用过滤器查询某些记录时,错误 channel 随机 返回零错误。 (这个例子指向我的开发数据库实例)。
要多次复制、编译和运行以下命令,您将看到返回的数据或崩溃:
package main
import (
"fmt"
"github.com/aerospike/aerospike-client-go"
)
func main() {
c, err := aerospike.NewClient("52.7.157.46", 3000)
if err != nil {
panic(err)
}
recs := liststuff(c)
fmt.Printf("got results: %v", recs)
}
func liststuff(client *aerospike.Client) []*aerospike.Record {
// fetch some records with a filter
stm := aerospike.NewStatement("test", "products")
stm.Addfilter(aerospike.NewEqualFilter("visible", 1))
fmt.Println("querying...")
recordset, err := client.Query(nil, stm)
if err != nil {
panic(err)
}
// collect results into a slice
recs := []*aerospike.Record{}
L:
for {
select {
case rec, chanOpen := <-recordset.Records:
if !chanOpen {
break L
}
fmt.Println("found record %v", rec)
recs = append(recs, rec)
case err := <-recordset.Errors:
if err != nil {
panic(err)
} else {
panic(fmt.Errorf("error nil when it should exist"))
}
return nil
}
}
return recs
}
最佳答案
只是为了发布更新,当服务器端的记录流结束时,Errors 和 Records channel 都会自动关闭,因此 Errors channel 的值为 nil。
所以这毕竟不是错误。我们相应地更新了 Aerospike 用户论坛帖子中的主题。
关于go - 将 Query() 与 Go 客户端一起使用时,Aerospike 随机返回 nil 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30676900/