Skip to content
roseduan edited this page Jun 19, 2022 · 1 revision

HSet

err = db.HSet([]byte("watermelon"), []byte("hash"), []byte("In summer, I love watermelon."))
if err != nil {
   fmt.Printf("HSet error: %v", err)
}

HSetNX

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)

HGet

value, err := db.HGet([]byte("watermelon"), []byte("hash"))
if err != nil {
   fmt.Printf("HGet error: %v", err)
}
fmt.Println(string(value))

HMGet

_ = 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))
}

HDel

res, err := db.HDel([]byte("my_hash"), []byte("f1"))
if err != nil {
   fmt.Printf("hdel err: %v", err)
   return
}
fmt.Println("hdel result : ", res)
Clone this wiki locally