ZPopMax Removes and returns the member with the highest score in the sorted set specified by key in a bucket.
(bucket string, key []byte)
| 145 | |
| 146 | // ZPopMax Removes and returns the member with the highest score in the sorted set specified by key in a bucket. |
| 147 | func (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. |
| 181 | func (tx *Tx) ZPopMin(bucket string, key []byte) (*SortedSetMember, error) { |