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

Method ZRangeByScore

tx_zset.go:284–319  ·  view source on GitHub ↗

ZRangeByScore Returns all the elements in the sorted set specified by key in a bucket with a score between min and max. And the parameter `Opts` is the same as ZCount's.

(bucket string, key []byte, start, end float64, opts *GetByScoreRangeOptions)

Source from the content-addressed store, hash-verified

282// ZRangeByScore Returns all the elements in the sorted set specified by key in a bucket with a score between min and max.
283// And the parameter `Opts` is the same as ZCount's.
284func (tx *Tx) ZRangeByScore(bucket string, key []byte, start, end float64, opts *GetByScoreRangeOptions) ([]*SortedSetMember, error) {
285 if err := tx.ZCheck(bucket); err != nil {
286 return nil, err
287 }
288
289 b, err := tx.db.bucketMgr.GetBucket(DataStructureSortedSet, bucket)
290 if err != nil {
291 return nil, err
292 }
293
294 var (
295 bucketId = b.Id
296 sortedSet *SortedSet
297 exist bool
298 )
299
300 if sortedSet, exist = tx.db.Index.SortedSet.exist(bucketId); !exist {
301 return nil, ErrBucket
302 }
303
304 records, scores, err := sortedSet.ZRangeByScore(string(key), SCORE(start), SCORE(end), opts)
305 if err != nil {
306 return nil, err
307 }
308
309 members := make([]*SortedSetMember, len(records))
310 for i, record := range records {
311 value, err := tx.db.getValueByRecord(record)
312 if err != nil {
313 return nil, err
314 }
315 members[i] = &SortedSetMember{Value: value, Score: scores[i]}
316 }
317
318 return members, nil
319}
320
321// ZRangeByRank Returns all the elements in the sorted set specified by key in a bucket
322// with a rank between start and end (including elements with rank equal to start or end).

Callers 2

TestTx_ZRangeByScoreFunction · 0.45
testZRangeByScoreFunction · 0.45

Calls 5

ZCheckMethod · 0.95
SCORETypeAlias · 0.85
GetBucketMethod · 0.80
existMethod · 0.80
getValueByRecordMethod · 0.80

Tested by 1

TestTx_ZRangeByScoreFunction · 0.36