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

Method ZMembers

tx_zset.go:54–92  ·  view source on GitHub ↗

ZMembers Returns all the members and scores of members of the set specified by key in a bucket.

(bucket string, key []byte)

Source from the content-addressed store, hash-verified

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) {
55 if err := tx.ZCheck(bucket); err != nil {
56 return nil, err
57 }
58
59 b, err := tx.db.bucketMgr.GetBucket(DataStructureSortedSet, bucket)
60 if err != nil {
61 return nil, err
62 }
63
64 var (
65 bucketId = b.Id
66 sortedSet *SortedSet
67 exist bool
68 )
69
70 if sortedSet, exist = tx.db.Index.SortedSet.exist(bucketId); !exist {
71 return nil, ErrBucket
72 }
73
74 members, err := sortedSet.ZMembers(string(key))
75 if err != nil {
76 return nil, err
77 }
78
79 res := make(map[*SortedSetMember]struct{})
80 for record, score := range members {
81 value, err := tx.db.getValueByRecord(record)
82 if err != nil {
83 return nil, err
84 }
85 res[&SortedSetMember{
86 Value: value,
87 Score: float64(score),
88 }] = struct{}{}
89 }
90
91 return res, nil
92}
93
94// ZCard Returns the sorted set cardinality (number of elements) of the sorted set specified by key in a bucket.
95func (tx *Tx) ZCard(bucket string, key []byte) (int, error) {

Callers 5

TestTx_ZMembersFunction · 0.45
testZMembersFunction · 0.45
testZRemFunction · 0.45
testZRemRangeByRankFunction · 0.45

Calls 4

ZCheckMethod · 0.95
GetBucketMethod · 0.80
existMethod · 0.80
getValueByRecordMethod · 0.80

Tested by 2

TestTx_ZMembersFunction · 0.36