GEOADD command with Redigo

huangapple go评论86阅读模式
英文:

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)...)

huangapple
  • 本文由 发表于 2017年1月28日 01:17:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/41899534.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定