@@ -11,7 +11,7 @@ Module net.box
11
11
The ``net.box `` module contains connectors to remote database systems. One
12
12
variant, to be discussed later, is for connecting to MySQL or MariaDB or PostgreSQL
13
13
(see :ref: `SQL DBMS modules <dbms_modules >` reference). The other variant, which
14
- is discussed in this section, is for connecting to Tarantool server instances via a
14
+ is discussed in this section, is for connecting to Tarantool server instances via a
15
15
network.
16
16
17
17
You can call the following methods:
@@ -147,80 +147,118 @@ Below is a list of all ``net.box`` functions.
147
147
148
148
.. function :: connect(URI [, {option[s]}])
149
149
150
+ The names ``connect() `` and ``new() `` are synonyms: ``connect() `` is
151
+ preferred; ``new() `` is retained for backward compatibility. For more
152
+ information, see the description of ``net_box.new() `` below.
153
+
150
154
.. _net_box-new :
151
155
152
156
.. function :: new(URI [, {option[s]}])
153
157
154
- .. NOTE ::
155
-
156
- The names ``connect() `` and ``new() `` are synonyms: ``connect() `` is
157
- preferred; ``new() `` is retained for backward compatibility.
158
-
159
158
Create a new connection. The connection is established on demand, at the
160
159
time of the first request. It can be re-established automatically after a
161
160
disconnect (see ``reconnect_after `` option below).
162
161
The returned ``conn `` object supports methods for making remote requests,
163
162
such as select, update or delete.
164
163
165
- Possible options:
166
-
167
- * `user/password `: you have two ways to connect to a remote host:
168
- using :ref: `URI <index-uri >` or using the options `user ` and `password `. For
169
- example, instead of ``connect('username:userpassword@localhost:33301') `` you
170
- can write ``connect('localhost:33301', {user = 'username', password='userpassword'}) ``.
171
-
172
- * `wait_connected `: by default, connection creation is blocked until the connection is established,
173
- but passing ``wait_connected=false `` makes it return immediately. Also, passing a timeout
174
- makes it wait before returning (e.g. ``wait_connected=1.5 `` makes it wait at most 1.5 seconds).
175
-
176
- .. NOTE ::
177
-
178
- If ``reconnect_after `` is greater than zero, then ``wait_connected `` ignores transient failures.
179
- The wait completes once the connection is established or is closed explicitly.
180
-
181
- * `reconnect_after `: if ``reconnect_after `` is greater than zero, then a ``net.box `` instance
182
- will try to reconnect if a connection is broken or if a connection attempt fails.
183
- This makes transient network failures become transparent to the application.
184
- Reconnect happens automatically in the background, so requests that
185
- initially fail due to connectivity loss are transparently retried.
186
- The number of retries is unlimited, connection attempts are made after each
187
- specified interval (for example ``reconnect_after=5 `` means try to reconnect every 5 seconds).
188
- When a connection is explicitly closed, or when the Lua garbage collector
189
- removes it, then reconnect attempts stop.
190
- The default value of ``reconnect_after ``, as with other ``connect `` options, is ``nil ``.
191
-
192
- * `call_16 `: [since 1.7.2] by default, ``net.box `` connections comply with a new
193
- binary protocol command for CALL, which is not backward compatible with previous versions.
194
- The new CALL no longer restricts a function to returning an array of tuples
195
- and allows returning an arbitrary MsgPack/JSON result, including scalars, nil and void (nothing).
196
- The old CALL is left intact for backward compatibility.
197
- It will be removed in the next major release.
198
- All programming language drivers will be gradually changed to use the new CALL.
199
- To connect to a Tarantool instance that uses the old CALL, specify ``call_16=true ``.
200
-
201
- * `console `: depending on the option's value, the connection supports different methods
202
- (as if instances of different classes were returned). With ``console = true ``, you can use
203
- ``conn `` methods ``close() ``, ``is_connected() ``, ``wait_state() ``, ``eval() `` (in this case, both
204
- binary and Lua console network protocols are supported). With ``console = false `` (default), you can
205
- also use ``conn `` database methods (in this case, only the binary protocol is supported).
206
- Deprecation notice: ``console = true `` is deprecated, users should use
207
- :ref: `console.connect() <console-connect >` instead.
208
-
209
- * `connect_timeout `: number of seconds to wait before returning "error: Connection timed out".
210
-
211
164
:param string URI: the :ref: `URI <index-uri >` of the target for the connection
212
- :param options: possible options are `user `, `password `, `wait_connected `,
213
- `reconnect_after `, `call_16 `, `console ` and `connect_timeout `
165
+ :param options: the supported options are shown below:
166
+
167
+ * ``user/password ``: two options to connect to a remote host other than through
168
+ :ref: `URI <index-uri >`. For example, instead of ``connect('username:userpassword@localhost:3301') ``
169
+ you can write ``connect('localhost:3301', {user = 'username', password='userpassword'}) ``.
170
+
171
+ * ``wait_connected ``: a connection timeout. By default, the connection is blocked until the connection
172
+ is established, but if you specify ``wait_connected=false ``, the connection returns immediately.
173
+ If you specify this timeout, it will wait before returning (``wait_connected=1.5 `` makes it wait at most 1.5 seconds).
174
+
175
+ .. NOTE ::
176
+
177
+ If ``reconnect_after `` is greater than zero, then ``wait_connected `` ignores transient failures.
178
+ The wait completes once the connection is established or is closed explicitly.
179
+
180
+
181
+ * ``reconnect_after ``: a number of seconds to wait before reconnecting.
182
+ The default value, as with the other ``connect `` options, is ``nil ``. If ``reconnect_after ``
183
+ is greater than zero, then a ``net.box `` instance will attempt to reconnect if a connection
184
+ is lost or a connection attempt fails. This makes transient network failures transparent to the application.
185
+ Reconnection happens automatically in the background, so requests that initially fail due to connection drops
186
+ fail, are transparently retried. The number of retries is unlimited, connection retries are made after
187
+ any specified interval (for example, ``reconnect_after=5 `` means that reconnect attempts are made every 5 seconds).
188
+ When a connection is explicitly closed or when the Lua garbage collector removes it, then reconnect attempts stop.
189
+
190
+
191
+ * ``call_16 ``: [since 1.7.2] a new binary protocol command for CALL in ``net.box `` connections by default.
192
+ The new CALL is not backward compatible with previous versions. It no longer restricts a function to
193
+ returning an array of tuples and allows returning an arbitrary MsgPack/JSON result,
194
+ including scalars, nil and void (nothing). The old CALL is left intact for backward compatibility.
195
+ It will not be present in the next major release. All programming language drivers will gradually be switched
196
+ to the new CALL. To connect to a Tarantool instance that uses the old CALL, specify ``call_16=true ``.
197
+
198
+ * ``console ``: an option to use different connection support methods (as if instances of different
199
+ classes are returned). With ``console = true ``, you can use the ``conn `` methods ``close() ``,
200
+ ``is_connected() ``, ``wait_state() ``, ``eval() `` (in this case both binary and Lua console
201
+ network protocols are supported).
202
+ With ``console = false `` (default), you can also use ``conn `` database methods (in this case only the
203
+ binary protocol is supported). Deprecation note: ``console = true `` is deprecated, users should use
204
+ :ref: `console.connect() <console-connect >` instead.
205
+
206
+ * ``connect_timeout ``: a number of seconds to wait before returning "error: Connection timed out".
207
+
208
+ * ``required_protocol_version ``: a minimum version of the :ref: `IPROTO protocol <box_protocol-id >`
209
+ supported by the server. If the version of the :ref: `IPROTO protocol <box_protocol-id >` supported
210
+ by the server is lower than specified, the connection will fail with an error message.
211
+ With ``required_protocol_version = 1 ``, all connections fail where the :ref: `IPROTO protocol <box_protocol-id >`
212
+ version is lower than ``1 ``.
213
+
214
+ * ``required_protocol_features ``: specified :ref: `IPROTO protocol features <box_protocol-id >` supported by the server.
215
+ You can specify one or more ``net.box `` features from the table below. If the server does not
216
+ support the specified features, the connection will fail with an error message.
217
+ With ``required_protocol_features = {'transactions'} ``, all connections fail where the
218
+ server has ``transactions: false ``.
219
+
220
+ .. container :: table
221
+
222
+ .. list-table ::
223
+ :widths: 26 29 25 20
224
+ :header-rows: 1
225
+
226
+ * - net.box feature
227
+ - Use
228
+ - IPROTO feature ID
229
+ - IPROTO protocol versions with the net.box feature support
230
+ * - ``streams ``
231
+ - Requires streams support on the server
232
+ - IPROTO_FEATURE_STREAMS
233
+ - 1 and newer
234
+ * - ``transactions ``
235
+ - Requires transactions support on the server
236
+ - IPROTO_FEATURE_TRANSACTIONS
237
+ - 1 and newer
238
+ * - ``error_extension ``
239
+ - Requires support for :ref: `MP_ERROR <msgpack_ext-error >` MsgPack extension on the server
240
+ - IPROTO_FEATURE_ERROR_EXTENSION
241
+ - 2 and newer
242
+ * - ``watchers ``
243
+ - Requires remote watchers support on the server
244
+ - IPROTO_FEATURE_WATCHERS
245
+ - 3 and newer
246
+
247
+ To learn more about IPROTO features, see :ref: `IPROTO_ID <box_protocol-id >`.
248
+
214
249
:return: conn object
215
250
:rtype: userdata
216
251
217
252
**Examples: **
218
253
219
254
.. code-block :: lua
220
255
256
+ net_box = require('net.box')
257
+
221
258
conn = net_box.connect('localhost:3301')
222
259
conn = net_box.connect('127.0.0.1:3302', {wait_connected = false})
223
260
conn = net_box.connect('127.0.0.1:3303', {reconnect_after = 5, call_16 = true})
261
+ conn = net_box.connect('127.0.0.1:3304', {required_protocol_version = 4, required_protocol_features = {'transactions', 'streams'}, })
224
262
225
263
.. _net_box-self :
226
264
@@ -624,7 +662,7 @@ Below is a list of all ``net.box`` functions.
624
662
625
663
.. _conn-new_stream :
626
664
627
- .. method :: stream ([options])
665
+ .. method :: new_stream ([options])
628
666
629
667
Create a stream.
630
668
0 commit comments