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

Function LPop

command/lists.go:68–92  ·  view source on GitHub ↗

LPop removes and returns the first element of the list stored at key

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

66
67// LPop removes and returns the first element of the list stored at key
68func 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
95func LRange(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
LPopMethod · 0.65

Tested by

no test coverage detected