如果记录首先不存在,我正在尝试将带有分数的记录添加到排序集中:
func (r *rDA) InsertIntoSortedSetIfNotExist(value int32, score int32) error {
conn, err := r.pool.GetContext(r.ctx)
if err != nil {
return err
}
defer conn.Close()
_, err = conn.Do("ZADD NX", "some_key", score, value) // err = "ERR command 'ZADD NX' is not supported."
return err
}
但是,这不适用于 ZADD NX
的错误。不支持。我试过这个,它也不起作用:
_, err = conn.Do("ZADD", "some_key", score, value, "NX") // err = "ERR syntax error"
如果有人知道如何使用 redigo 使用 ZADD NX 命令,将不胜感激。谢谢!
最佳答案
您面临的问题是由于 NX 放置错误
conn.Do("ZADD", "some_key", "NX",score, value)
redis 的命令在 NX 上是这样使用的ZADD NAME NX 2 'Jhon'
您也可以在 https://redis.io/commands/zadd#zadd-options-redis-302-or-greater 查看文档ZADD supports a list of options, specified after the name of the key and before the first score argument.
关于go - 使用带有选项标志的 ZADD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64023420/