Skip to content

Commit 870e4a7

Browse files
Add config.storage TTL option
This patch adds a time-to-live (TTL) option to `config.storage` API methods. This option allows one to put keys that will expire when the passed time passes. Closes tarantool/enterprise_doc#281
1 parent 7e4faf6 commit 870e4a7

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

doc/reference/reference_lua/config.rst

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,16 @@ The ``config.storage`` API allows you to interact with a Tarantool-based :ref:`c
395395

396396
.. _config_storage_api_reference_put:
397397

398-
.. function:: put(path, value)
398+
.. function:: put(path, value, opts)
399399

400400
Put a value by the specified path.
401401

402402
:param string path: a path to put the value by
403403
:param string value: a value to put
404+
:param table opts: a table containing the following optional fields:
405+
406+
* ``ttl`` (since :doc:`3.2.0 </release/3.2.0>`, default: unset): time-to-live in seconds, if nil or not set the key won't expire, may issue an error if set on config.storage running old schema, see :ref:`config.storage.info <config_storage_api_reference_info>`.
407+
404408

405409
:return: a table containing the following fields:
406410

@@ -516,9 +520,25 @@ The ``config.storage`` API allows you to interact with a Tarantool-based :ref:`c
516520
* ``connected``: if any instance from the quorum is available to the current instance
517521
* ``disconnected``: if the current instance doesn't have a connection with the quorum
518522

523+
* ``features`` (since :doc:`3.2.0 </release/3.2.0>`): a table of features config.storage supports, may include the following:
524+
525+
* ``ttl``: true if key TTL (time-to-live) is supported, false otherwise if the schema hasn't been upgraded yet
526+
527+
519528
:rtype: table
520529

521530

531+
**Example:**
532+
533+
The example below shows how to check whether config.storage supports keys TTL:
534+
535+
.. code-block:: lua
536+
537+
local info = config.storage.info
538+
if info.features == nil or not info.features.ttl then
539+
error('...')
540+
end
541+
522542
.. _config_storage_api_reference_txn:
523543

524544
.. function:: txn(request)
@@ -542,6 +562,17 @@ The ``config.storage`` API allows you to interact with a Tarantool-based :ref:`c
542562

543563
* ``on_failure``: a list with operations to execute if any of a predicate evaluates to ``false``
544564

565+
Operations in ``on_success`` and ``on_failure`` follow the format:
566+
567+
.. code-block:: none
568+
569+
{operation, key_or_path[, value][, opts]}
570+
571+
* ``operation``: one of ``'put'``, ``'get'``, ``'delete'``
572+
* ``opts``: a table containing optional fields for the operations:
573+
574+
* ``ttl`` (since :doc:`3.2.0 </release/3.2.0>`, default: unset): time-to-live for a key in seconds, if nil or not set the key won't expire
575+
545576
:return: a table containing the following fields:
546577

547578
* ``data``: a table containing response data:
@@ -608,12 +639,17 @@ Examples on GitHub: `config_storage <https://github.com/tarantool/doc/tree/lates
608639

609640
.. _config_storage_client_api_reference_put:
610641

611-
.. function:: <config.storage client>:put(path, value)
642+
.. function:: <config.storage client>:put(path, value, opts)
612643

613644
Put a value by the specified path to remote config.storage.
614645

615646
:param string path: a path to put the value by
616647
:param string value: a value to put
648+
:param table opts: a table containing the following optional fields:
649+
650+
* ``ttl`` (since :doc:`3.2.0 </release/3.2.0>`, default: unset): time-to-live in seconds, if nil or not set the key won't expire, may issue an error if set on config.storage running old schema, see :ref:`<config.storage client>.info <config_storage_client_api_reference_info>`.
651+
652+
617653

618654
:return: a table containing the following fields:
619655

@@ -727,9 +763,26 @@ Get information about a connection state to the config.storage cluster.
727763
* ``connected``: if any instance from the quorum is available to the current instance
728764
* ``disconnected``: if the current instance doesn't have a connection with the quorum
729765

766+
* ``features`` (since :doc:`3.2.0 </release/3.2.0>`): a table of features config.storage supports, may include the following:
767+
768+
* ``ttl``: true if key TTL (time-to-live) is supported, false otherwise if the schema hasn't been upgraded yet
769+
770+
730771
:rtype: table
731772

732773

774+
**Example:**
775+
776+
The example below shows how to check whether remote config.storage supports keys TTL:
777+
778+
.. code-block:: lua
779+
780+
local info = storage_client.info
781+
if info.features == nil or not info.features.ttl then
782+
error('...')
783+
end
784+
785+
733786
.. _config_storage_client_api_reference_txn:
734787

735788
.. function:: <config.storage client>:txn(request)
@@ -753,6 +806,18 @@ Make an atomic request on remote config.storage.
753806

754807
* ``on_failure``: a list with operations to execute if any of a predicate evaluates to ``false``
755808

809+
Operations in ``on_success`` and ``on_failure`` follow the format:
810+
811+
.. code-block:: none
812+
813+
{operation, key_or_path[, value][, opts]}
814+
815+
* ``operation``: one of ``'put'``, ``'get'``, ``'delete'``
816+
* ``opts``: a table containing optional fields for the operations:
817+
818+
* ``ttl`` (since :doc:`3.2.0 </release/3.2.0>`, default: unset): time-to-live for a key in seconds, if nil or not set the key won't expire
819+
820+
756821
:return: a table containing the following fields:
757822

758823
* ``data``: a table containing response data:

0 commit comments

Comments
 (0)