-
Notifications
You must be signed in to change notification settings - Fork 639
String
roseduan edited this page May 23, 2022
·
3 revisions
err = db.Set([]byte("name"), []byte("RoseDB"))
if err != nil {
fmt.Printf("write data err: %v", err)
return
}
err = db.SetEX([]byte("type"), []byte("RoseDB-Strs"), time.Second*5)
if err != nil {
fmt.Printf("write data err: %v", err)
return
}
err = db.SetNX([]byte("cmd"), []byte("SetNX"))
if err != nil {
fmt.Printf("write data err: %v", err)
return
}
err = db.MSet([]byte("key-1"), []byte("value-1"), []byte("key-2"), []byte("value-2"))
if err != nil {
fmt.Printf("mset error: %v\n", err)
return
}
err = db.MSetNX([]byte("key-11"), []byte("value-11"), []byte("key-22"), []byte("value-22"))
if err != nil {
fmt.Printf("msetnx error: %v\n", err)
}
val, _ := db.Get([]byte("key-11"))
fmt.Printf("key-11: %v\n", string(val))
v, err := db.Get([]byte("name"))
if err != nil {
fmt.Printf("read data err: %v", err)
return
}
fmt.Println("val = ", string(v))
keys := [][]byte{
[]byte("key-1"),
[]byte("not exist"),
[]byte("key-11"),
}
vals, err := db.MGet(keys)
if err != nil {
fmt.Printf("mget err : %v\n", err)
} else {
fmt.Printf("mget values : %v\n", vals)
}
err = db.Delete([]byte("name"))
if err != nil {
fmt.Printf("delete data err: %v", err)
}
_, err = db.GetDel([]byte("not-exist"))
if err != nil {
fmt.Printf("getdel data err: %v", err)
}
gdVal, err := db.GetDel([]byte("key-22"))
if err != nil {
fmt.Printf("getdel data err: %v", err)
} else {
fmt.Println("getdel val : ", string(gdVal))
}