(m uhaha.Machine, args []string)
| 432 | } |
| 433 | |
| 434 | func cmdZREVRANGEBYSCORE(m uhaha.Machine, args []string) (interface{}, error) { |
| 435 | if len(args) < 4 { |
| 436 | return nil, uhaha.ErrWrongNumArgs |
| 437 | } |
| 438 | |
| 439 | min, max, err := zparseScoreRange([]byte(args[3]), []byte(args[2])) |
| 440 | if err != nil { |
| 441 | return nil, err |
| 442 | } |
| 443 | |
| 444 | key := args[1] |
| 445 | |
| 446 | args = args[4:] |
| 447 | var withScores bool |
| 448 | if len(args) > 0 { |
| 449 | if strings.ToLower(args[0]) == "withscores" { |
| 450 | withScores = true |
| 451 | args = args[1:] |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | var offset int |
| 456 | count := -1 |
| 457 | if len(args) > 0 { |
| 458 | if len(args) != 3 { |
| 459 | return nil, uhaha.ErrWrongNumArgs |
| 460 | } |
| 461 | |
| 462 | if strings.ToLower(args[0]) != "limit" { |
| 463 | return nil, uhaha.ErrWrongNumArgs |
| 464 | } |
| 465 | |
| 466 | if offset, err = strconv.Atoi(args[1]); err != nil { |
| 467 | return nil, uhaha.ErrWrongNumArgs |
| 468 | } |
| 469 | |
| 470 | if count, err = strconv.Atoi(args[2]); err != nil { |
| 471 | return nil, uhaha.ErrWrongNumArgs |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | if offset < 0 { |
| 476 | //for ledis, if offset < 0, a empty will return |
| 477 | //so here we directly return a empty array |
| 478 | return [][]byte{}, nil |
| 479 | } |
| 480 | |
| 481 | scorePair, err := ldb.ZRangeByScoreGeneric([]byte(key), min, max, offset, count, true) |
| 482 | if err != nil { |
| 483 | return nil, err |
| 484 | } |
| 485 | |
| 486 | if withScores { |
| 487 | ret := make([][]byte, len(scorePair)*2) |
| 488 | for index, item := range scorePair { |
| 489 | ret[index*2] = item.Member |
| 490 | ret[index*2+1] = []byte(strconv.Itoa(int(item.Score))) |
| 491 | } |
nothing calls this directly
no test coverage detected