LRange get a range of elements from a list
(ctx *Context, txn *db.Transaction)
| 93 | |
| 94 | // LRange get a range of elements from a list |
| 95 | func LRange(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 96 | args := ctx.Args |
| 97 | key := []byte(args[0]) |
| 98 | |
| 99 | start, err := strconv.ParseInt(args[1], 10, 64) |
| 100 | if err != nil { |
| 101 | return nil, ErrInteger |
| 102 | } |
| 103 | stop, err := strconv.ParseInt(args[2], 10, 64) |
| 104 | if err != nil { |
| 105 | return nil, ErrInteger |
| 106 | } |
| 107 | |
| 108 | lst, err := txn.List(key) |
| 109 | if err != nil { |
| 110 | if err == db.ErrTypeMismatch { |
| 111 | return nil, ErrTypeMismatch |
| 112 | } |
| 113 | return nil, errors.New("ERR " + err.Error()) |
| 114 | } |
| 115 | |
| 116 | if !lst.Exist() { |
| 117 | return BytesArray(ctx.Out, nil), nil |
| 118 | } |
| 119 | |
| 120 | items, err := lst.Range(start, stop) |
| 121 | if err != nil { |
| 122 | return nil, errors.New("ERR " + err.Error()) |
| 123 | } |
| 124 | if len(items) == 0 { |
| 125 | return BytesArray(ctx.Out, nil), nil |
| 126 | } |
| 127 | return BytesArray(ctx.Out, items), nil |
| 128 | } |
| 129 | |
| 130 | // LInsert insert an element before or after another element in a list |
| 131 | func LInsert(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected