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)
| 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 |
| 175 | func 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 |
| 197 | func Object(ctx *Context, txn *db.Transaction) (OnCommit, error) { |