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

Function PSetEx

command/strings.go:323–346  ·  view source on GitHub ↗

PSetEx sets the value and expiration in milliseconds of a key

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

321
322// PSetEx sets the value and expiration in milliseconds of a key
323func PSetEx(ctx *Context, txn *db.Transaction) (OnCommit, error) {
324 //get the key
325 key := []byte(ctx.Args[0])
326 obj, err := txn.Object(key)
327 if err != nil && err != db.ErrKeyNotFound {
328 return nil, errors.New("ERR " + err.Error())
329 }
330
331 if err != db.ErrKeyNotFound {
332 txn.Destory(obj, key)
333 }
334
335 s := db.NewString(txn, key)
336 ui, err := strconv.ParseUint(ctx.Args[1], 10, 64)
337 if err != nil {
338 return nil, ErrInteger
339 }
340 unit := ui * uint64(time.Millisecond)
341 if err := s.Set([]byte(ctx.Args[2]), int64(unit)); err != nil {
342 return nil, errors.New("ERR " + err.Error())
343 }
344
345 return SimpleString(ctx.Out, OK), nil
346}
347
348//SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.
349func SetRange(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
NewStringFunction · 0.92
SimpleStringFunction · 0.85
ObjectMethod · 0.80
ErrorMethod · 0.65
DestoryMethod · 0.65

Tested by

no test coverage detected