當我在 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 關注
- 381 瀏覽
添加回答
舉報
0/150
提交
取消