• SMoveByTwoBuckets
    SMoveByTwoBuckets

    将member从source集合移动到destination集合中。其中source集合和destination集合在两个不同的bucket中。

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