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

Function GetRange

command/strings.go:241–270  ·  view source on GitHub ↗

GetRange increments the integer value of a keys by the given amount

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

239
240// GetRange increments the integer value of a keys by the given amount
241func 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
273func SetNx(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 6

NullBulkStringFunction · 0.85
BulkStringFunction · 0.85
GetRangeMethod · 0.80
ErrorMethod · 0.65
ExistMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected