-
Notifications
You must be signed in to change notification settings - Fork 639
Hash
roseduan edited this page Jun 19, 2022
·
1 revision
err = db.HSet([]byte("watermelon"), []byte("hash"), []byte("In summer, I love watermelon."))
if err != nil {
fmt.Printf("HSet error: %v", err)
}
ok, err := db.HSetNX([]byte("key-1"), []byte("field-1"), []byte("value-1"))
if err != nil {
fmt.Printf("HSetNx error: %v", err)
}
fmt.Println(ok)
value, err := db.HGet([]byte("watermelon"), []byte("hash"))
if err != nil {
fmt.Printf("HGet error: %v", err)
}
fmt.Println(string(value))
_ = db.HSet([]byte("my_hash"), []byte("f1"), []byte("val-1"), []byte("f2"), []byte("val-2"))
values, err := db.HMGet([]byte("my_hash"), []byte("f1"), []byte("f2"))
if err != nil {
fmt.Printf("hmget err: %v", err)
return
}
fmt.Println("\n-----hmget results-----")
for _, v := range values {
fmt.Println(string(v))
}
res, err := db.HDel([]byte("my_hash"), []byte("f1"))
if err != nil {
fmt.Printf("hdel err: %v", err)
return
}
fmt.Println("hdel result : ", res)