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

Function GetSet

command/strings.go:219–238  ·  view source on GitHub ↗

GetSet sets the string value of a key and return its old value

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

217
218// GetSet sets the string value of a key and return its old value
219func GetSet(ctx *Context, txn *db.Transaction) (OnCommit, error) {
220 key := []byte(ctx.Args[0])
221 v := []byte(ctx.Args[1])
222 str, err := txn.String(key)
223 if err != nil {
224 if err == db.ErrTypeMismatch {
225 return nil, ErrTypeMismatch
226 }
227 return nil, errors.New("ERR " + err.Error())
228 }
229 if !str.Exist() {
230 return NullBulkString(ctx.Out), nil
231 }
232
233 value, err := str.GetSet(v)
234 if err != nil {
235 return nil, errors.New("ERR " + err.Error())
236 }
237 return BulkString(ctx.Out, string(value)), nil
238}
239
240// GetRange increments the integer value of a keys by the given amount
241func GetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected