MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / cmdZREVRANGE

Function cmdZREVRANGE

sorted_sets.go:194–239  ·  view source on GitHub ↗
(m uhaha.Machine, args []string)

Source from the content-addressed store, hash-verified

192}
193
194func cmdZREVRANGE(m uhaha.Machine, args []string) (interface{}, error) {
195 if len(args) < 4 {
196 return nil, uhaha.ErrWrongNumArgs
197 }
198
199 min, max, err := zparseRange(args[2], args[3])
200 if err != nil {
201 return nil, err
202 }
203
204 ScorePair, err := ldb.ZRevRange([]byte(args[1]), int(min), int(max))
205 if err != nil {
206 return nil, err
207 }
208
209 var withScores bool
210 args = args[4:]
211 if len(args) > 0 {
212 if len(args) != 1 {
213 return nil, uhaha.ErrWrongNumArgs
214 }
215 if strings.ToLower(args[0]) == "withscores" {
216 withScores = true
217 } else {
218 return nil, uhaha.ErrSyntax
219 }
220 }
221
222 if withScores {
223 ret := make([][]byte, len(ScorePair)*2)
224
225 for index, item := range ScorePair {
226 ret[index*2] = item.Member
227 ret[index*2+1] = []byte(strconv.Itoa(int(item.Score)))
228 }
229 return ret, nil
230 }
231
232 ret := make([][]byte, len(ScorePair))
233
234 for index, item := range ScorePair {
235 ret[index] = item.Member
236 }
237
238 return ret, nil
239}
240
241func cmdZRANK(m uhaha.Machine, args []string) (interface{}, error) {
242 if len(args) != 3 {

Callers

nothing calls this directly

Calls 1

zparseRangeFunction · 0.85

Tested by

no test coverage detected