MCPcopy Create free account
hub / github.com/distributedio/titan / RPopLPush

Function RPopLPush

command/lists.go:317–346  ·  view source on GitHub ↗

RPopLPush remove the last element in a list, prepend it to another list and return it

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

315
316// RPopLPush remove the last element in a list, prepend it to another list and return it
317func 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
349func RPush(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 7

NullBulkStringFunction · 0.85
BulkStringFunction · 0.85
ListMethod · 0.80
ErrorMethod · 0.65
ExistMethod · 0.65
RPopMethod · 0.65
LPushMethod · 0.65

Tested by

no test coverage detected