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)
| 113 | |
| 114 | // PExpire works exactly like expire but the time to live of the key is specified in milliseconds instead of seconds |
| 115 | func 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 |