Set Expire
Sets or update the expiration date of a key.
- Parameters:
key
: The key to set the expiration date for.expiresAt
: The expiration date to set as Date object or number of milliseconds.
- Returns:
- The result of the operation, includes a boolean indicating whether the operation was successful or an error if the operation failed.
// Date object expiration
if (db.setExpire("user:1234", new Date("2028-12-31")).success) {
console.log("Expiration date set successfully");
} else {
console.log(result.error.message);
}
// Number of milliseconds expiration
if (db.setExpire("user:1234", 90000).success) {
console.log("Expiration date set successfully");
} else {
console.log(result.error.message);
}