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

Function PExpire

command/keys.go:115–131  ·  view source on GitHub ↗

PExpire works exactly like expire but the time to live of the key is specified in milliseconds instead of seconds

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

113
114// PExpire works exactly like expire but the time to live of the key is specified in milliseconds instead of seconds
115func PExpire(ctx *Context, txn *db.Transaction) (OnCommit, error) {
116 kv := txn.Kv()
117 key := []byte(ctx.Args[0])
118 ms, err := strconv.ParseInt(ctx.Args[1], 10, 64)
119 if err != nil {
120 return nil, ErrInteger
121 }
122 at := time.Now().Add(time.Millisecond * time.Duration(ms)).UnixNano()
123 if err := kv.ExpireAt(key, at); err != nil {
124 if err == db.ErrKeyNotFound {
125 return Integer(ctx.Out, 0), nil
126 }
127 return nil, errors.New("ERR " + err.Error())
128 }
129 return Integer(ctx.Out, 1), nil
130
131}
132
133// PExpireAt has the same effect and semantic as expireAt,
134// but the Unix time at which the key will expire is specified in milliseconds instead of seconds

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