(m uhaha.Machine, args []string)
| 363 | } |
| 364 | |
| 365 | func cmdZRANGEBYSCORE(m uhaha.Machine, args []string) (interface{}, error) { |
| 366 | if len(args) < 4 { |
| 367 | return nil, uhaha.ErrWrongNumArgs |
| 368 | } |
| 369 | |
| 370 | min, max, err := zparseScoreRange([]byte(args[2]), []byte(args[3])) |
| 371 | if err != nil { |
| 372 | return nil, err |
| 373 | } |
| 374 | |
| 375 | key := args[1] |
| 376 | |
| 377 | args = args[4:] |
| 378 | var withScores bool |
| 379 | if len(args) > 0 { |
| 380 | if strings.ToLower(args[0]) == "withscores" { |
| 381 | withScores = true |
| 382 | args = args[1:] |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | var offset int |
| 387 | count := -1 |
| 388 | if len(args) > 0 { |
| 389 | if len(args) != 3 { |
| 390 | return nil, uhaha.ErrWrongNumArgs |
| 391 | } |
| 392 | |
| 393 | if strings.ToLower(args[0]) != "limit" { |
| 394 | return nil, uhaha.ErrWrongNumArgs |
| 395 | } |
| 396 | |
| 397 | if offset, err = strconv.Atoi(args[1]); err != nil { |
| 398 | return nil, uhaha.ErrWrongNumArgs |
| 399 | } |
| 400 | |
| 401 | if count, err = strconv.Atoi(args[2]); err != nil { |
| 402 | return nil, uhaha.ErrWrongNumArgs |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | if offset < 0 { |
| 407 | //for ledis, if offset < 0, a empty will return |
| 408 | //so here we directly return a empty array |
| 409 | return [][]byte{}, nil |
| 410 | } |
| 411 | |
| 412 | scorePair, err := ldb.ZRangeByScore([]byte(key), min, max, offset, count) |
| 413 | if err != nil { |
| 414 | return nil, err |
| 415 | } |
| 416 | |
| 417 | if withScores { |
| 418 | ret := make([][]byte, len(scorePair)*2) |
| 419 | for index, item := range scorePair { |
| 420 | ret[index*2] = item.Member |
| 421 | ret[index*2+1] = []byte(strconv.Itoa(int(item.Score))) |
| 422 | } |
nothing calls this directly
no test coverage detected