class MeshConnection

class tarantool.mesh_connection.MeshConnection(host=None, port=None, user=None, password=None, socket_timeout=None, reconnect_max_attempts=10, reconnect_delay=0.1, connect_now=True, encoding=None, call_16=False, connection_timeout=None, addrs=None, strategy_class=<class 'tarantool.mesh_connection.RoundRobinStrategy'>, cluster_discovery_function=None, cluster_discovery_delay=60)

Represents a connection to a cluster of Tarantool servers.

This class uses Connection to connect to one of the nodes of the cluster. The initial list of nodes is passed to the constructor in ‘addrs’ parameter. The class set in ‘strategy_class’ parameter is used to select a node from the list and switch nodes in case of unavailability of the current node.

‘cluster_discovery_function’ param of the constructor sets the name of a stored Lua function used to refresh the list of available nodes. The function takes no parameters and returns a list of strings in format ‘host:port’. A generic function for getting the list of nodes looks like this:

function get_cluster_nodes()
    return {
        -- ...

You may put in this list whatever you need depending on your cluster topology. Chances are you’ll want to make the list of nodes from nodes’ replication config. Here is an example for it:

local uri_lib = require('uri')

function get_cluster_nodes()
    local nodes = {}

    local replicas = box.cfg.replication

    for i = 1, #replicas do
        local uri = uri_lib.parse(replicas[i])

        if and uri.service then
            table.insert(nodes, .. ':' .. uri.service)

    -- if your replication config doesn't contain the current node
    -- you have to add it manually like this:
    table.insert(nodes, '')

    return nodes