RPopLPush remove the last element in a list, prepend it to another list and return it
(ctx *Context, txn *db.Transaction)
| 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) { |
| 318 | listsrc, err := txn.List([]byte(ctx.Args[0])) |
| 319 | if err != nil { |
| 320 | if err == db.ErrTypeMismatch { |
| 321 | return nil, ErrTypeMismatch |
| 322 | } |
| 323 | return nil, errors.New("ERR " + err.Error()) |
| 324 | } |
| 325 | |
| 326 | if !listsrc.Exist() { |
| 327 | return NullBulkString(ctx.Out), nil |
| 328 | } |
| 329 | val, err := listsrc.RPop() |
| 330 | if err != nil { |
| 331 | return nil, errors.New("ERR " + err.Error()) |
| 332 | } |
| 333 | |
| 334 | // create dst list on not exist |
| 335 | listdst, err := txn.List([]byte(ctx.Args[1])) |
| 336 | if err != nil { |
| 337 | if err == db.ErrTypeMismatch { |
| 338 | return nil, ErrTypeMismatch |
| 339 | } |
| 340 | return nil, ErrSyntax |
| 341 | } |
| 342 | if err = listdst.LPush(val); err != nil { |
| 343 | return nil, ErrTypeMismatch |
| 344 | } |
| 345 | return BulkString(ctx.Out, string(val)), nil |
| 346 | } |
| 347 | |
| 348 | // RPush append one or multiple values to a list |
| 349 | func RPush(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected