Err0r500
Err0r500

Reputation: 25

GEOADD command with Redigo

Here's what i'm trying, using Redigo ("github.com/garyburd/redigo/redis") :

insertPos := []string{"3.361389", "38.115556", "12"}
if _, err := conn.Do("GEOADD", redis.Args{}.Add("geoIndex").AddFlat(&insertPos)...); err != nil {
    log.Print(err)
} 
==> "ERR wrong number of arguments for 'geoadd' command"

While with the redis-cli this works fine :

GEOADD geoIndex  3.361389  38.115556  12
==> (integer) 1

Other commands works fine, that's just the first time I've to use GEOADD and it clearly doesn't seem to work as I expect it to. Does someone have an idea ?

Upvotes: 2

Views: 514

Answers (1)

Thundercat
Thundercat

Reputation: 120979

The easiest way to call this API is:

_, err := conn.Do("GEOADD", "geoIndex", "3.361389", "38.115556", "12")

You can also pass number values:

_, err := conn.Do("GEOADD", "geoIndex", 3.361389, 38.115556, 12)

If you do want to piece the command together, then pass the slice to AddFlat, not a pointer to the slice:

insertPos := []string{"3.361389", "38.115556", "12"}
_, err := conn.Do("GEOADD", redis.Args{}.Add("geoIndex").AddFlat(insertPos)...)

Upvotes: 2

Related Questions