Skip to content

Get Key Expiration Time

Description

This operation retrieves the expiration time for a key. The expiration time is expressed as a number of seconds until the key expires. Note that all keys are created without timeouts by default, and you can set it by invoking the "Set Key Expiration - TTL" or the "Set Key Expiration - Unix time" operations.

Method

GET

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]/get-expiration-ttl

where:

Argument                Description
[hive-name] Name of a hive where the operation is performed.
[bucket-type] Storage type in the [hive-name] Hive where to get the expiration value for a key. Acceptable values are list, key-value, map, set or sorted-set.
[key] Key name to get the timeout value for.

Request Headers

None.

Request Body

None.

Response Body

The number of seconds until a specific key expires.

If the specified key does not exist, then the following Backendless error is returned:

{  
    "code": 27003,  
    "message": "no such key",  
    "errorData": {}  
}

If the specified key has no timeouts set, then the following Backendless error is returned:

{  
    "code": 27010,  
    "message": "Expiration for key wasn't set.",  
    "errorData": {}  
}

Example

The example below checks if a timeout is set on the fruits key, and returns the number of seconds until expiration of the key.

curl --location --request GET "https://xxxx.backendless.app/api/hive/groceryStore/list/fruits/get-expiration-ttl"

where:

Argument                Description
groceryStore Name of a hive where the operation is performed.
fruits Key name in the store to check the expiration time.

Codeless Reference
general_api_get_key_expiration_time

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 get the timeout value for.

Returns the number of seconds until a specific key expires.

Consider the following Key Value storage:

sample-key-value

The example below gets the timeout value for the "Japan" key:

general_api_example_get_key_expiration_time
The output will look as shown below after the Codeless logic runs.
general_api_example_get_key_expiration_time_2