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

LPush

err = db.LPush([]byte("students"), []byte("Tom"), []byte("Jame"), []byte("Ming"))
if err != nil {
   fmt.Printf("write data err: %v", err)
   return
}

LPushX

err = db.LPushX([]byte("not-exist"), []byte("Tom"))
fmt.Println(err) // ErrKeyNotFound
err = db.LPushX([]byte("students"), []byte("Rose"))
if err != nil {
   fmt.Printf("write data err: %v", err)
   return
}

RPush

err = db.RPush([]byte("students"), []byte("Jack"), []byte("Wei"))
if err != nil {
   fmt.Printf("write data err: %v", err)
   return
}

RPushX

err = db.RPushX([]byte("not-exist"), []byte("Jack"))
fmt.Println(err) // ErrKeyNotFound
err = db.RPushX([]byte("students"), []byte("Duan"))
if err != nil {
   fmt.Printf("write data err: %v", err)
   return
}

LPop

lPopStu, err := db.LPop([]byte("students"))
if err != nil {
   fmt.Printf("lpop data err: %v", err)
   return
}
fmt.Println(string(lPopStu))

RPop

rPopStu, err := db.RPop([]byte("students"))
if err != nil {
   fmt.Printf("rpop data err: %v", err)
   return
}
fmt.Println(string(rPopStu))
Clone this wiki locally