-
Notifications
You must be signed in to change notification settings - Fork 639
List
roseduan edited this page Jun 12, 2022
·
1 revision
err = db.LPush([]byte("students"), []byte("Tom"), []byte("Jame"), []byte("Ming"))
if err != nil {
fmt.Printf("write data err: %v", err)
return
}
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
}
err = db.RPush([]byte("students"), []byte("Jack"), []byte("Wei"))
if err != nil {
fmt.Printf("write data err: %v", err)
return
}
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
}
lPopStu, err := db.LPop([]byte("students"))
if err != nil {
fmt.Printf("lpop data err: %v", err)
return
}
fmt.Println(string(lPopStu))
rPopStu, err := db.RPop([]byte("students"))
if err != nil {
fmt.Printf("rpop data err: %v", err)
return
}
fmt.Println(string(rPopStu))