LIndex get an element from a list by its index
(ctx *Context, txn *db.Transaction)
| 165 | |
| 166 | //LIndex get an element from a list by its index |
| 167 | func LIndex(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 168 | key := []byte(ctx.Args[0]) |
| 169 | n, err := strconv.ParseInt(string(ctx.Args[1]), 10, 64) |
| 170 | if err != nil { |
| 171 | return nil, ErrInteger |
| 172 | } |
| 173 | |
| 174 | lst, err := txn.List(key) |
| 175 | if err != nil { |
| 176 | if err == db.ErrTypeMismatch { |
| 177 | return nil, ErrTypeMismatch |
| 178 | } |
| 179 | return nil, errors.New("ERR " + err.Error()) |
| 180 | } |
| 181 | if !lst.Exist() { |
| 182 | return NullBulkString(ctx.Out), nil |
| 183 | } |
| 184 | val, err := lst.Index(n) |
| 185 | if err != nil { |
| 186 | if err == db.ErrOutOfRange { |
| 187 | return NullBulkString(ctx.Out), nil |
| 188 | } |
| 189 | return nil, errors.New("ERR " + err.Error()) |
| 190 | |
| 191 | } |
| 192 | return BulkString(ctx.Out, string(val)), nil |
| 193 | } |
| 194 | |
| 195 | //LLen get the length of a list |
| 196 | func LLen(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected