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

Function ExpireAt

command/keys.go:70–91  ·  view source on GitHub ↗

ExpireAt sets an absolute timestamp to expire on key

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

68
69// ExpireAt sets an absolute timestamp to expire on key
70func ExpireAt(ctx *Context, txn *db.Transaction) (OnCommit, error) {
71 kv := txn.Kv()
72 key := []byte(ctx.Args[0])
73 timestamp, err := strconv.ParseInt(ctx.Args[1], 10, 64)
74 if err != nil {
75 return nil, ErrInteger
76 }
77
78 at := int64(time.Second * time.Duration(timestamp))
79 if at <= 0 {
80 at = 1
81 }
82
83 if err := kv.ExpireAt(key, at); err != nil {
84 if err == db.ErrKeyNotFound {
85 return Integer(ctx.Out, 0), nil
86 }
87 return nil, errors.New("ERR " + err.Error())
88 }
89
90 return Integer(ctx.Out, 1), nil
91}
92
93// Persist removes the existing timeout on key, turning the key from volatile to persistent
94func Persist(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