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

Method ZAdd

tx_zset.go:37–51  ·  view source on GitHub ↗

ZAdd Adds the specified member with the specified score into the sorted set specified by key in a bucket.

(bucket string, key []byte, score float64, val []byte)

Source from the content-addressed store, hash-verified

35
36// ZAdd Adds the specified member with the specified score into the sorted set specified by key in a bucket.
37func (tx *Tx) ZAdd(bucket string, key []byte, score float64, val []byte) error {
38 var buffer bytes.Buffer
39
40 if strings.Contains(string(key), SeparatorForZSetKey) {
41 return ErrSeparatorForZSetKey()
42 }
43
44 buffer.Write(key)
45 buffer.Write([]byte(SeparatorForZSetKey))
46 scoreBytes := []byte(strconv.FormatFloat(score, 'f', -1, 64))
47 buffer.Write(scoreBytes)
48 newKey := buffer.Bytes()
49
50 return tx.put(bucket, newKey, val, Persistent, DataZAddFlag, uint64(time.Now().Unix()), DataStructureSortedSet)
51}
52
53// ZMembers Returns all the members and scores of members of the set specified by key in a bucket.
54func (tx *Tx) ZMembers(bucket string, key []byte) (map[*SortedSetMember]struct{}, error) {

Calls 3

putMethod · 0.95
ErrSeparatorForZSetKeyFunction · 0.85
WriteMethod · 0.65