SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.
(ctx *Context, txn *db.Transaction)
| 347 | |
| 348 | //SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. |
| 349 | func SetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 350 | offset, err := strconv.Atoi(ctx.Args[1]) |
| 351 | if err != nil { |
| 352 | return nil, ErrInteger |
| 353 | } |
| 354 | |
| 355 | key := []byte(ctx.Args[0]) |
| 356 | if offset < 0 || offset > MaxRangeInteger { |
| 357 | return nil, ErrMaximum |
| 358 | } |
| 359 | |
| 360 | str, err := txn.String(key) |
| 361 | if err != nil { |
| 362 | if err == db.ErrTypeMismatch { |
| 363 | return nil, ErrTypeMismatch |
| 364 | } |
| 365 | return nil, errors.New("ERR " + err.Error()) |
| 366 | } |
| 367 | |
| 368 | // If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit. |
| 369 | val, err := str.SetRange(int64(offset), []byte(ctx.Args[2])) |
| 370 | if err != nil { |
| 371 | return nil, errors.New("ERR " + err.Error()) |
| 372 | } |
| 373 | return Integer(ctx.Out, int64(len(val))), nil |
| 374 | |
| 375 | } |
| 376 | |
| 377 | // Incr increments the integer value of a key by one |
| 378 | func Incr(ctx *Context, txn *db.Transaction) (OnCommit, error) { |