英文:
GEOADD command with Redigo
问题
这是我正在尝试的代码,使用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"
而使用redis-cli,这个命令可以正常工作:
GEOADD geoIndex 3.361389 38.115556 12
==> (integer) 1
其他命令都可以正常工作,只是这是我第一次使用GEOADD命令,它显然不像我期望的那样工作。有人有什么想法吗?
英文:
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 ?
答案1
得分: 2
调用此API的最简单方法是:
_, err := conn.Do("GEOADD", "geoIndex", "3.361389", "38.115556", "12")
您也可以传递数字值:
_, err := conn.Do("GEOADD", "geoIndex", 3.361389, 38.115556, 12)
如果您确实想要将命令拼接在一起,那么将切片传递给AddFlat,而不是切片的指针:
insertPos := []string{"3.361389", "38.115556", "12"}
_, err := conn.Do("GEOADD", redis.Args{}.Add("geoIndex").AddFlat(insertPos)...)
英文:
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)...)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论