I’m experiencing some strange behavior. I’m trying to set up a small webapp that fetches some data using Aerospike 3.5 Community running on an Ubuntu 12.04 server. I’m using the default aerospike.conf file (using the ‘test’ namespace) and am following the example of how to query here.
When I attempt to query some records with a filter, the Errors channel randomly is returning a nil error. (This example points to my dev database instance).
To replicate, compile and run the following multiple times, you’ll see either data returned or a panic:
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
}