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

Function LTrim

command/lists.go:239–266  ·  view source on GitHub ↗

LTrim trim a list to the specified range

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

237
238//LTrim trim a list to the specified range
239func LTrim(ctx *Context, txn *db.Transaction) (OnCommit, error) {
240 key := []byte(ctx.Args[0])
241 start, err := strconv.ParseInt(ctx.Args[1], 10, 64)
242 if err != nil {
243 return nil, ErrInteger
244 }
245 stop, err := strconv.ParseInt(ctx.Args[2], 10, 64)
246 if err != nil {
247 return nil, ErrInteger
248 }
249 lst, err := txn.List(key)
250 if err != nil {
251 if err == db.ErrTypeMismatch {
252 return nil, ErrTypeMismatch
253 }
254 return nil, errors.New("ERR " + err.Error())
255 }
256
257 if !lst.Exist() {
258 return BulkString(ctx.Out, "OK"), nil
259 }
260 if err = lst.LTrim(start, stop); err != nil {
261 return nil, errors.New("ERR " + err.Error())
262 }
263
264 return BulkString(ctx.Out, "OK"), nil
265
266}
267
268//LSet set the value of an element in a list by its index
269func LSet(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 5

BulkStringFunction · 0.85
ListMethod · 0.80
ErrorMethod · 0.65
ExistMethod · 0.65
LTrimMethod · 0.65

Tested by

no test coverage detected