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

Function Expire

command/keys.go:51–67  ·  view source on GitHub ↗

Expire sets a timeout on key

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

49
50// Expire sets a timeout on key
51func Expire(ctx *Context, txn *db.Transaction) (OnCommit, error) {
52 kv := txn.Kv()
53 key := []byte(ctx.Args[0])
54 seconds, err := strconv.ParseInt(ctx.Args[1], 10, 64)
55 if err != nil {
56 return nil, ErrInteger
57 }
58
59 at := time.Now().Add(time.Second * time.Duration(seconds)).UnixNano()
60 if err := kv.ExpireAt(key, at); err != nil {
61 if err == db.ErrKeyNotFound {
62 return Integer(ctx.Out, 0), nil
63 }
64 return nil, errors.New("ERR " + err.Error())
65 }
66 return Integer(ctx.Out, 1), nil
67}
68
69// ExpireAt sets an absolute timestamp to expire on key
70func ExpireAt(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 4

IntegerFunction · 0.85
KvMethod · 0.80
ExpireAtMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected