Tarantool code examples | Tarantool
Tarantool code examples

Tarantool code examples

The doc/code_snippets folder of a Tarantool documentation repository contains runnable code examples that show how to work with Tarantool:

  • The snippets folder contains sample applications that demonstrate how to configure a Tarantool cluster.
  • The test folder contains testable Lua examples that show how to work with various Tarantool modules.

Code from these examples is referenced in corresponding documentation sections.

  • Install the tt CLI utility.

  • To be able to run tests for samples from test, go to the doc/code_snippets folder and install the following libraries:

To run applications placed in snippets, follow these steps:

  1. Go to the directory containing samples for a specific feature, for example, snippets/replication.

  2. To run applications placed in instances.enabled, execute the tt start command, for example:

    $ tt start auto_leader

To test all the examples, go to the doc/code_snippets folder and execute the luatest command:


To test the examples from the specified directory, pass its relative path to the luatest command:

.rocks/bin/luatest test/transactions

To test a specific example with the stdout output enabled, use the luatest command with the -c option, for example:

.rocks/bin/luatest -c test/http_client/get_test.lua

Note that the HTTP client samples (placed in test/http_client) use the httpbin service. You can run httpbin locally using Docker to stabilize test results:

docker run -p 80:80 kennethreitz/httpbin

In this case, you need to replace https://httpbin.org links with

To display a specific source file in a topic, use the literalinclude directive as follows:

..  literalinclude:: /code_snippets/test/http_client/post_json_test.lua
    :language: lua
    :lines: 1-6
Found what you were looking for?