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

Function LSet

command/lists.go:269–293  ·  view source on GitHub ↗

LSet set the value of an element in a list by its index

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

267
268//LSet set the value of an element in a list by its index
269func LSet(ctx *Context, txn *db.Transaction) (OnCommit, error) {
270 key := []byte(ctx.Args[0])
271 lst, err := txn.List(key)
272 if err != nil {
273 if err == db.ErrTypeMismatch {
274 return nil, ErrTypeMismatch
275 }
276 return nil, errors.New("ERR " + err.Error())
277 }
278
279 if !lst.Exist() {
280 return nil, ErrNoSuchKey
281 }
282 n, err := strconv.ParseInt(ctx.Args[1], 10, 64)
283 if err != nil {
284 return nil, ErrInteger
285 }
286 if err := lst.Set(n, []byte(ctx.Args[2])); err != nil {
287 if err == db.ErrOutOfRange {
288 return nil, ErrIndex
289 }
290 return nil, errors.New("ERR " + err.Error())
291 }
292 return SimpleString(ctx.Out, "OK"), nil
293}
294
295//RPop remove and get the last element in a list
296func RPop(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 5

SimpleStringFunction · 0.85
ListMethod · 0.80
ErrorMethod · 0.65
ExistMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected