当我在 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}
1 回答

UYOU
TA贡献1878条经验 获得超4个赞
你可以在 Go 中使用 hset 代替 hmset :
_, err := r.Conn.Do("hset", article, map[string]interface{}{
"title": title,
"link": link,
"poster": user,
"time": now,
"votes": 1,
}).Result()
- 1 回答
- 0 关注
- 358 浏览
添加回答
举报
0/150
提交
取消