ExpireAt sets an absolute timestamp to expire on key
(ctx *Context, txn *db.Transaction)
| 68 | |
| 69 | // ExpireAt sets an absolute timestamp to expire on key |
| 70 | func 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 |
| 94 | func Persist(ctx *Context, txn *db.Transaction) (OnCommit, error) { |