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

Method ZPopMax

tx_zset.go:147–178  ·  view source on GitHub ↗

ZPopMax Removes and returns the member with the highest score in the sorted set specified by key in a bucket.

(bucket string, key []byte)

Source from the content-addressed store, hash-verified

145
146// ZPopMax Removes and returns the member with the highest score in the sorted set specified by key in a bucket.
147func (tx *Tx) ZPopMax(bucket string, key []byte) (*SortedSetMember, error) {
148 if err := tx.ZCheck(bucket); err != nil {
149 return nil, err
150 }
151
152 b, err := tx.db.bucketMgr.GetBucket(DataStructureSortedSet, bucket)
153 if err != nil {
154 return nil, err
155 }
156
157 var (
158 bucketId = b.Id
159 sortedSet *SortedSet
160 exist bool
161 )
162
163 if sortedSet, exist = tx.db.Index.SortedSet.exist(bucketId); !exist {
164 return nil, ErrBucket
165 }
166
167 record, score, err := sortedSet.ZPeekMax(string(key))
168 if err != nil {
169 return nil, err
170 }
171
172 value, err := tx.db.getValueByRecord(record)
173 if err != nil {
174 return nil, err
175 }
176
177 return &SortedSetMember{Value: value, Score: float64(score)}, tx.put(bucket, key, []byte(""), Persistent, DataZPopMaxFlag, uint64(time.Now().Unix()), DataStructureSortedSet)
178}
179
180// ZPopMin Removes and returns the member with the lowest score in the sorted set specified by key in a bucket.
181func (tx *Tx) ZPopMin(bucket string, key []byte) (*SortedSetMember, error) {

Callers 3

buildSortedSetIdxMethod · 0.45
txZPopFunction · 0.45
testZPopMaxFunction · 0.45

Calls 6

ZCheckMethod · 0.95
putMethod · 0.95
GetBucketMethod · 0.80
existMethod · 0.80
getValueByRecordMethod · 0.80
ZPeekMaxMethod · 0.45

Tested by 1

txZPopFunction · 0.36