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

Function RPop

command/lists.go:296–314  ·  view source on GitHub ↗

RPop remove and get the last element in a list

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

294
295//RPop remove and get the last element in a list
296func 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
317func RPopLPush(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected