LPop removes and returns the first element of the list stored at key
(ctx *Context, txn *db.Transaction)
| 66 | |
| 67 | // LPop removes and returns the first element of the list stored at key |
| 68 | func LPop(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 69 | args := ctx.Args |
| 70 | |
| 71 | // number of args should be checked by caller |
| 72 | key := []byte(args[0]) |
| 73 | |
| 74 | lst, err := txn.List(key) |
| 75 | |
| 76 | if err != nil { |
| 77 | if err == db.ErrTypeMismatch { |
| 78 | return nil, ErrTypeMismatch |
| 79 | } |
| 80 | return nil, errors.New("ERR " + err.Error()) |
| 81 | } |
| 82 | |
| 83 | if !lst.Exist() { |
| 84 | return NullBulkString(ctx.Out), nil |
| 85 | } |
| 86 | |
| 87 | val, err := lst.LPop() |
| 88 | if err != nil { |
| 89 | return nil, errors.New("ERR " + err.Error()) |
| 90 | } |
| 91 | return BulkString(ctx.Out, string(val)), nil |
| 92 | } |
| 93 | |
| 94 | // LRange get a range of elements from a list |
| 95 | func LRange(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected