去redis HMSet失败

go redis HMSet fail

当我在 Go 中使用 redis hmset 时出现以下问题,这是为什么? ERR wrong number of arguments for 'hset' command 导致值未存储在 redis 中? 我指的是 redis 的书,为什么会出现这个问题?

func (r *ArticleRepo) PostArticle(user, title, link string) string {
    articleId := strconv.Itoa(int(r.Conn.Incr("article:").Val()))

    voted := "voted:" + articleId
    r.Conn.SAdd(voted, user)
    r.Conn.Expire(voted, common.OneWeekInSeconds*time.Second)

    now := time.Now().Unix()
    article := "article:" + articleId
    _, err := r.Conn.HMSet(article, map[string]interface{}{
        "title":  title,
        "link":   link,
        "poster": user,
        "time":   now,
        "votes":  1,
    }).Result()
    if err != nil {
        fmt.Println(err)
    }

    r.Conn.ZAdd("score:", &redis.Z{Score: float64(now + common.VoteScore), Member: article})
    r.Conn.ZAdd("time:", &redis.Z{Score: float64(now), Member: article})
    return articleId
}

你可以在 Go 中使用 hset 而不是 hmset 与这样的东西:

 _, err := r.Conn.Do("hset", article, map[string]interface{}{
    "title":  title,
    "link":   link,
    "poster": user,
    "time":   now,
    "votes":  1,
}).Result()