I'm developing with Go lang and very new to it. I would like to use the redis GEORADIUS command and get back my results including the distance.
I have now used two packages radix.v2 and redigo to try and get results but had no joy. I have no issues using simple commands such as SET and GET.
Any help will be greatly appreciated.
Edit: added code :-)
package main
import (
"fmt"
"github.com/mediocregopher/radix.v2/redis"
//"reflect"
"encoding/json"
)
var (
client *redis.Client
)
type Facility struct {
Id string
Dist string
}
func main() {
client, err := redis.Dial("tcp", "192.168.99.100:6379")
if err != nil {
// handle err
}
surname, err := client.Cmd("GET", "surname").Str()
if err != nil {
// handle err
}
fmt.Println(surname)
reply, _ := client.Cmd("GEORADIUS", "venues", 50, 0, 25, "mi", "WITHDIST", "ASC").Array()
if err != nil {
fmt.Println(err)
}
//fmt.Println(reflect.TypeOf(reply))
//fmt.Println(reply)
var facilities []Facility
for _, results := range reply {
facility, _ := results.Array()
id, _ := facility[0].Str()
dist, _ := facility[1].Str()
facilities = append(facilities, Facility{
Id: id,
Dist: dist,
})
}
//fmt.Println(facilities)
resp, _ := json.Marshal(facilities)
fmt.Fprintf(w, string(resp))
}
Cheers Stephen