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

Function LRange

command/lists.go:95–128  ·  view source on GitHub ↗

LRange get a range of elements from a list

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

93
94// LRange get a range of elements from a list
95func LRange(ctx *Context, txn *db.Transaction) (OnCommit, error) {
96 args := ctx.Args
97 key := []byte(args[0])
98
99 start, err := strconv.ParseInt(args[1], 10, 64)
100 if err != nil {
101 return nil, ErrInteger
102 }
103 stop, err := strconv.ParseInt(args[2], 10, 64)
104 if err != nil {
105 return nil, ErrInteger
106 }
107
108 lst, err := txn.List(key)
109 if err != nil {
110 if err == db.ErrTypeMismatch {
111 return nil, ErrTypeMismatch
112 }
113 return nil, errors.New("ERR " + err.Error())
114 }
115
116 if !lst.Exist() {
117 return BytesArray(ctx.Out, nil), nil
118 }
119
120 items, err := lst.Range(start, stop)
121 if err != nil {
122 return nil, errors.New("ERR " + err.Error())
123 }
124 if len(items) == 0 {
125 return BytesArray(ctx.Out, nil), nil
126 }
127 return BytesArray(ctx.Out, items), nil
128}
129
130// LInsert insert an element before or after another element in a list
131func LInsert(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 5

BytesArrayFunction · 0.85
ListMethod · 0.80
ErrorMethod · 0.65
ExistMethod · 0.65
RangeMethod · 0.65

Tested by

no test coverage detected