當我在 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
}
uj5u.com熱心網友回復:
你可以在 Go 中使用 hset 而不是 hmset 像這樣:
_, err := r.Conn.Do("hset", article, map[string]interface{}{
"title": title,
"link": link,
"poster": user,
"time": now,
"votes": 1,
}).Result()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/347817.html
上一篇:去安裝github.com/dmacvicar/terraform-provider-libvirt@latest-顯示錯誤
