本文整理匯總了Golang中github.com/hoisie/redis.Client.Hmset方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Hmset方法的具體用法?Golang Client.Hmset怎麽用?Golang Client.Hmset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hoisie/redis.Client
的用法示例。
在下文中一共展示了Client.Hmset方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
client := redis.Client{Addr: "192.168.1.101:6379"}
// client.Addr = "127.0.0.1:6379"
client.Hmset("h1", map[string]string{"Key3": "abc", "Key4": "sdfs",
"key1": "abc", "key2": "sdfs"})
m := make(map[string]string)
client.Hgetall("h1", m)
log.Println(m)
a := AA{}
client.Hgetall("h1", &a)
log.Println(a)
}
示例2: postArticle
func postArticle(client redis.Client, user, title, link string) string {
id, err := client.Incr("article:")
if err != nil {
log.Fatal("Incrエラーだよ", err.Error())
}
articleID := strconv.FormatInt(id, 20)
voted := "voted:" + articleID
if _, err := client.Sadd(voted, []byte(user)); err != nil {
log.Fatal("Saddエラーだよ", err.Error())
}
if _, err := client.Expire(voted, int64(ONE_WEEK_DAY*time.Second)); err != nil {
log.Fatal("Expireエラーだよ", err.Error())
}
now := time.Now()
article := "article:" + articleID
fmt.Println("articleID", articleID)
if err := client.Hmset(article, map[string]string{
"title": title,
"link": link,
"poster": user,
"time": now.String(),
"votes": "1",
}); err != nil {
log.Fatal("Hmsetエラーだよ", err.Error())
}
if _, err := client.Zadd("score:", []byte(article), float64(now.Unix()+VOTE_SCORE)); err != nil {
log.Fatal("Zaddエラーだよ", err.Error())
}
if _, err := client.Zadd("time:", []byte(article), float64(now.Unix())); err != nil {
log.Fatal("Zaddエラーだよ", err.Error())
}
return articleID
}