MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / sPut

Method sPut

tx_set.go:37–85  ·  view source on GitHub ↗
(bucket string, key []byte, dataFlag uint16, values ...[]byte)

Source from the content-addressed store, hash-verified

35)
36
37func (tx *Tx) sPut(bucket string, key []byte, dataFlag uint16, values ...[]byte) error {
38
39 if dataFlag == DataSetFlag {
40
41 filter := make(map[uint32]struct{})
42
43 b1, err := tx.db.bucketMgr.GetBucket(DataStructureSet, bucket)
44 if err != nil {
45 return err
46 }
47 bucketId := b1.Id
48
49 if set, ok := tx.db.Index.Set.exist(bucketId); ok {
50
51 if _, ok := set.M[string(key)]; ok {
52 for hash := range set.M[string(key)] {
53 filter[hash] = struct{}{}
54 }
55 }
56
57 }
58
59 for _, value := range values {
60 hash, err := utils.GetFnv32(value)
61 if err != nil {
62 return err
63 }
64 if _, ok := filter[hash]; !ok {
65 filter[hash] = struct{}{}
66 err := tx.put(bucket, key, value, Persistent, dataFlag, uint64(time.Now().Unix()), DataStructureSet)
67 if err != nil {
68 return err
69 }
70 }
71 }
72
73 } else {
74 for _, value := range values {
75
76 err := tx.put(bucket, key, value, Persistent, dataFlag, uint64(time.Now().Unix()), DataStructureSet)
77 if err != nil {
78 return err
79 }
80
81 }
82 }
83
84 return nil
85}
86
87// SAdd adds the specified members to the set stored int the bucket at given bucket,key and items.
88func (tx *Tx) SAdd(bucket string, key []byte, items ...[]byte) error {

Callers 3

SAddMethod · 0.95
SRemMethod · 0.95
SPopMethod · 0.95

Calls 4

putMethod · 0.95
GetFnv32Function · 0.92
GetBucketMethod · 0.80
existMethod · 0.80

Tested by

no test coverage detected