- ZRem
ZRem
删除指定成员key在一个指定的有序集合bucket中。
if err := db.Update(
func(tx *nutsdb.Tx) error {
bucket := "myZSet5"
key1 := []byte("key1")
return tx.ZAdd(bucket, key1, 10, []byte("val1"))
}); err != nil {
log.Fatal(err)
}
if err := db.Update(
func(tx *nutsdb.Tx) error {
bucket := "myZSet5"
key2 := []byte("key2")
return tx.ZAdd(bucket, key2, 20, []byte("val2"))
}); err != nil {
log.Fatal(err)
}
if err := db.View(
func(tx *nutsdb.Tx) error {
bucket := "myZSet5"
if nodes,err := tx.ZMembers(bucket); err != nil {
return err
} else {
fmt.Println("before ZRem key1, ZMembers nodes",nodes)
for _,node:=range nodes {
fmt.Println("item:",node.Key(),node.Score())
}
}
// before ZRem key1, ZMembers nodes map[key1:0xc00008cfa0 key2:0xc00008d090]
// item: key1 10
// item: key2 20
return nil
}); err != nil {
log.Fatal(err)
}
if err := db.Update(
func(tx *nutsdb.Tx) error {
bucket := "myZSet5"
if err := tx.ZRem(bucket, "key1"); err != nil {
return err
}
return nil
}); err != nil {
log.Fatal(err)
}
if err := db.View(
func(tx *nutsdb.Tx) error {
bucket := "myZSet5"
if nodes,err := tx.ZMembers(bucket); err != nil {
return err
} else {
fmt.Println("after ZRem key1, ZMembers nodes",nodes)
for _,node:=range nodes {
fmt.Println("item:",node.Key(),node.Score())
}
// after ZRem key1, ZMembers nodes map[key2:0xc00008d090]
// item: key2 20
}
return nil
}); err != nil {
log.Fatal(err)
}