LSet set the value of an element in a list by its index
(ctx *Context, txn *db.Transaction)
| 267 | |
| 268 | //LSet set the value of an element in a list by its index |
| 269 | func 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 |
| 296 | func RPop(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected