gpt4 book ai didi

go - 使用带有选项标志的 ZADD

转载 作者:行者123 更新时间:2023-12-01 22:20:08 25 4
gpt4 key购买 nike

如果记录首先不存在,我正在尝试将带有分数的记录添加到排序集中:

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 keyand before the first score argument.

关于go - 使用带有选项标志的 ZADD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64023420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com