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

Function PTTL

command/keys.go:175–194  ·  view source on GitHub ↗

PTTL likes TTL this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds

(ctx *Context, txn *db.Transaction)

Source from the content-addressed store, hash-verified

173// PTTL likes TTL this command returns the remaining time to live of a key that has an expire set,
174// with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds
175func PTTL(ctx *Context, txn *db.Transaction) (OnCommit, error) {
176 key := []byte(ctx.Args[0])
177 now := db.Now()
178 obj, err := txn.Object(key)
179 if err != nil {
180 if err == db.ErrKeyNotFound {
181 return Integer(ctx.Out, -2), nil
182 }
183 return nil, errors.New("ERR " + err.Error())
184 }
185 if db.IsExpired(obj, now) {
186 return Integer(ctx.Out, -2), nil
187 }
188 if obj.ExpireAt == 0 {
189 return Integer(ctx.Out, -1), nil
190 }
191 ttl := (obj.ExpireAt - now) / int64(time.Millisecond)
192 return Integer(ctx.Out, ttl), nil
193
194}
195
196// Object inspects the internals of Redis Objects
197func Object(ctx *Context, txn *db.Transaction) (OnCommit, error) {

Callers

nothing calls this directly

Calls 5

NowFunction · 0.92
IsExpiredFunction · 0.92
IntegerFunction · 0.85
ObjectMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected