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

Backendless.Hive(hiveName).[bucketType](keyName).getExpiration(): Promise<number>;

where:

Argument                Description
hiveName Name of a hive where the operation is performed. String value.
[bucketType] This placeholder must be substituted with one of the following stores types: KeyValueStore, ListStore, MapStore, SetStore, SortedSetStore.
keyName Key name to get the timeout value for. String value.

Return Value

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.

await Backendless.Hive('groceryStore').ListStore('fruits').getExpiration()

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