GetRange increments the integer value of a keys by the given amount
(ctx *Context, txn *db.Transaction)
| 239 | |
| 240 | // GetRange increments the integer value of a keys by the given amount |
| 241 | func GetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
| 242 | key := ctx.Args[0] |
| 243 | str, err := txn.String([]byte(key)) |
| 244 | if err != nil { |
| 245 | if err == db.ErrTypeMismatch { |
| 246 | return nil, ErrTypeMismatch |
| 247 | } |
| 248 | return nil, errors.New("ERR " + err.Error()) |
| 249 | } |
| 250 | |
| 251 | start, err := strconv.Atoi(ctx.Args[1]) |
| 252 | if err != nil { |
| 253 | return nil, ErrInteger |
| 254 | } |
| 255 | end, err := strconv.Atoi(ctx.Args[2]) |
| 256 | if err != nil { |
| 257 | return nil, ErrInteger |
| 258 | } |
| 259 | |
| 260 | if !str.Exist() { |
| 261 | return NullBulkString(ctx.Out), nil |
| 262 | } |
| 263 | |
| 264 | value := str.GetRange(start, end) |
| 265 | if len(value) == 0 { |
| 266 | return NullBulkString(ctx.Out), nil |
| 267 | } |
| 268 | |
| 269 | return BulkString(ctx.Out, string(value)), nil |
| 270 | } |
| 271 | |
| 272 | // SetNx sets the value of a key ,only if the key does not exist |
| 273 | func SetNx(ctx *Context, txn *db.Transaction) (OnCommit, error) { |
nothing calls this directly
no test coverage detected