Skip to content

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

PUT

Endpoint URL

Important

Make sure to replace xxxx in the domain name in the request specification below to the one assigned to your application.

https://xxxx.backendless.app/api/hive/[hive-name]/[bucket-type]/[key]/expire-at?unixTime=[seconds]

where:

Argument                Description
[hive-name] Name of a hive where the operation is performed.
[bucket-type] Storage type in the[hive-name] Hive where a timeout will be set for a key. Acceptable values are list, key-value, map, set or sorted-set.
[key] Key name to set a timeout for.
[seconds] A Unix timestamp identifying a moment in time when the key-value pair must expire and be subsequently removed from the store.

Request Headers

None.

Request Body

None.

Response Body

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:

curl --location --request PUT "https://xxxx.backendless.app/api/hive/groceryStore/list/fruits/expire-at?unixTime=1653567283"

where:

Argument                Description
groceryStore Name of a hive where the operation is performed.
fruits Key name to set a timeout for.

Codeless Reference

general_api_set_key_expiration_timestamp

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:

sample-key-value

The example below sets an expiration timeout on the "Japan" key, then the key gets deleted from the store at the 1684000000  Unix time:

general_api_example_set_key_expiration_timestamp