首先,让我展示如何重现我的问题:
在 docker 容器中运行 Redis
连接到 Redis 并执行以下命令:
> SET test 10
在 Go 中,运行以下代码:
func main() {
redisClient := getConnection() // Abstracting get connection for simplicity
r, err := redisClient.Do("HSET", "test", "f1", "v1", "f2", "v2")
fmt.Printf("%+v e: %+v\n")
}
很公平,在此步骤中显示以下错误(这意味着err != nil):
WRONGTYPE Operation against a key holding the wrong kind of value e: WRONGTYPE Operation against a key holding the wrong kind of value
相比之下,执行以下代码:
func main() {
redisClient := getConnection()
redisClient.Send("MULTI")
redisClient.Send("HSET", "test", "f1", "v1", "f2", "v2")
r, err := redisClient.Do("EXEC")
fmt.Printf("%+v e: %+v\n")
}
正在打印的行是:
WRONGTYPE Operation against a key holding the wrong kind of value e: <nil>
这对我来说似乎不一致,因为我也希望在错误变量中MULTI返回。WRONGTYPE
这是预期的行为还是我错过了什么?
饮歌长啸
相关分类