Set Key Expiration - Unix Time¶
Description¶
This operation relies on the Unix time, which is the number of seconds elapsed since 1970-01-01 00:00:00 UTC
till the present moment. The number of seconds must be passed to the operation in the Unix time format to set the timeout, for instance: the Unix time for October 20, 2022
is 1666213200
seconds. When a timeout is set for a key, the system deletes the key at the specified time. Note that all keys are created without timeouts by default. This operation provides a way to set an absolute timeout value as a timestamp.
Method¶
Backendless.Hive(hiveName).StoreType(key).expireAt(unixTimeSeconds);
where:
Argument | Description |
---|---|
hiveName |
Name of a hive where the operation is performed. String value. |
StoreType |
This placeholder must be substituted with one of the following stores types: KeyValueStore , ListStore , MapStore , SetStore , SortedSetStore . |
key |
Key name to set the expiration timeout for. String value. |
unixTimeSeconds |
A Unix timestamp identifying a moment in time when the key-value pair must expire and be subsequently removed from the store. Integer value. |
Return Value¶
None.
If the specified key does not exist, returns the following Backendless error:
{
"code": 27003,
"message": "no such key",
"errorData": {}
}
Example¶
The example below sets a timeout for the "fruits"
key:
Backendless.Hive("groceryStore").ListStore("fruits").expireAt(1684000000);
where:
Argument | Description |
---|---|
"groceryStore" |
Name of a hive where the operation is performed. |
"fruits" |
Key name to set a timeout for. |
Codeless Reference¶
where:
Argument | Description |
---|---|
hive name |
Name of a hive where the operation is performed. |
type |
Storage type, can be one of the following: Key / Value, Sorted Set, Set, Map, List. |
key name |
Key name to set a timeout for. |
expire |
Expiration timeout type. Can be set to seconds after or on timestamp/date . The after seconds identifies the number of seconds until the key expires. The timestamp identifies a Unix timestamp/date when the key must expire. This option expects the number of seconds in the Unix format representing the exact date and time set for the key expiration. |
Consider the following Key Value storage:
The example below sets an expiration timeout on the "Japan"
key, then the key gets deleted from the store at the 1684000000
Unix time: