(m uhaha.Machine, args []string)
| 145 | } |
| 146 | |
| 147 | func cmdZRANGE(m uhaha.Machine, args []string) (interface{}, error) { |
| 148 | if len(args) < 4 { |
| 149 | return nil, uhaha.ErrWrongNumArgs |
| 150 | } |
| 151 | |
| 152 | min, max, err := zparseRange(args[2], args[3]) |
| 153 | if err != nil { |
| 154 | return nil, err |
| 155 | } |
| 156 | |
| 157 | ScorePair, err := ldb.ZRange([]byte(args[1]), int(min), int(max)) |
| 158 | if err != nil { |
| 159 | return nil, err |
| 160 | } |
| 161 | |
| 162 | var withScores bool |
| 163 | args = args[4:] |
| 164 | if len(args) > 0 { |
| 165 | if len(args) != 1 { |
| 166 | return nil, uhaha.ErrWrongNumArgs |
| 167 | } |
| 168 | if strings.ToLower(args[0]) == "withscores" { |
| 169 | withScores = true |
| 170 | } else { |
| 171 | return nil, uhaha.ErrSyntax |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if withScores { |
| 176 | ret := make([][]byte, len(ScorePair)*2) |
| 177 | |
| 178 | for index, item := range ScorePair { |
| 179 | ret[index*2] = item.Member |
| 180 | ret[index*2+1] = []byte(strconv.Itoa(int(item.Score))) |
| 181 | } |
| 182 | return ret, nil |
| 183 | } |
| 184 | |
| 185 | ret := make([][]byte, len(ScorePair)) |
| 186 | |
| 187 | for index, item := range ScorePair { |
| 188 | ret[index] = item.Member |
| 189 | } |
| 190 | |
| 191 | return ret, nil |
| 192 | } |
| 193 | |
| 194 | func cmdZREVRANGE(m uhaha.Machine, args []string) (interface{}, error) { |
| 195 | if len(args) < 4 { |
nothing calls this directly
no test coverage detected