• SMoveByOneBucket
    SMoveByOneBucket

    将member从source集合移动到destination集合中,其中source集合和destination集合均在一个bucket中。

    1. bucket3 := "bucket3"
    2. if err := db.Update(
    3. func(tx *nutsdb.Tx) error {
    4. return SAdd(bucket3, []byte("mySet1"), []byte("a"), []byte("b"), []byte("c"))
    5. }); err != nil {
    6. log.Fatal(err)
    7. }
    8. if err := db.Update(
    9. func(tx *nutsdb.Tx) error {
    10. return tx.SAdd(bucket3, []byte("mySet2"), []byte("c"), []byte("d"), []byte("e"))
    11. }); err != nil {
    12. log.Fatal(err)
    13. }
    14. if err := db.Update(
    15. func(tx *nutsdb.Tx) error {
    16. if ok, err := tx.SMoveByOneBucket(bucket3, []byte("mySet1"), []byte("mySet2"), []byte("a")); err != nil {
    17. return err
    18. } else {
    19. fmt.Println("SMoveByOneBucket", ok)
    20. }
    21. return nil
    22. }); err != nil {
    23. log.Fatal(err)
    24. }
    25. if err := db.View(
    26. func(tx *nutsdb.Tx) error {
    27. if items, err := tx.SMembers(bucket3, []byte("mySet1")); err != nil {
    28. return err
    29. } else {
    30. fmt.Println("after SMoveByOneBucket bucket3 mySet1 SMembers", items)
    31. for _, item := range items {
    32. fmt.Println("item", string(item))
    33. }
    34. }
    35. return nil
    36. }); err != nil {
    37. log.Fatal(err)
    38. }
    39. if err := db.View(
    40. func(tx *nutsdb.Tx) error {
    41. if items, err := tx.SMembers(bucket3, []byte("mySet2")); err != nil {
    42. return err
    43. } else {
    44. fmt.Println("after SMoveByOneBucket bucket3 mySet2 SMembers", items)
    45. for _, item := range items {
    46. fmt.Println("item", string(item))
    47. }
    48. }
    49. return nil
    50. }); err != nil {
    51. log.Fatal(err)
    52. }