Skip to content

Set Key Expiration - TTL

Description

This operation sets a time-to-live(TTL) timeout on a specific key. When the timeout expires, they key and the corresponding value are deleted. Note that, all keys are created without timeouts by default. This operation enables the timeout functionality.

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?ttl=[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 key timeout should be set. Acceptable values are list, key-value, map, set or sorted-set.
[key] Key name to set a timeout for.
[seconds] A timeout value in seconds. When the specified number of seconds elapses after the operation is complete, the key-value pair expires and is 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 the 60 seconds timeout for the fruits key, once the timeout expires, the key gets deleted from the list store.

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

where:

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

Codeless Reference
general_api_set_key_expiration_ttl

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 for 100 seconds, once the timeout expires, the "Japan" key gets deleted from the store.

general_api_example_set_key_expiration_ttl