RPop remove and get the last element in a list
(ctx *Context, txn *db.Transaction)
| 294 | |
| 295 | //RPop remove and get the last element in a list |
| 296 | func RPop(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 297 | key := []byte(ctx.Args[0]) |
| 298 | lst, err := txn.List(key) |
| 299 | if err != nil { |
| 300 | if err == db.ErrTypeMismatch { |
| 301 | return nil, ErrTypeMismatch |
| 302 | } |
| 303 | return nil, errors.New("ERR " + err.Error()) |
| 304 | } |
| 305 | |
| 306 | if !lst.Exist() { |
| 307 | return NullBulkString(ctx.Out), nil |
| 308 | } |
| 309 | val, err := lst.RPop() |
| 310 | if err != nil { |
| 311 | return nil, errors.New("ERR " + err.Error()) |
| 312 | } |
| 313 | return BulkString(ctx.Out, string(val)), nil |
| 314 | } |
| 315 | |
| 316 | // RPopLPush remove the last element in a list, prepend it to another list and return it |
| 317 | func RPopLPush(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected