You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-16Lines changed: 91 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Code architecture and some features in version 3 borrowed from the [ioredis](htt
26
26
27
27
## Installation
28
28
29
-
```
29
+
```Bash
30
30
npm install --save tarantool-driver
31
31
```
32
32
## Configuration
@@ -38,18 +38,26 @@ Creates a Tarantool instance, extends [EventEmitter](http://nodejs.org/api/event
38
38
Connection related custom events:
39
39
* "reconnecting" - emitted when the client try to reconnect, first argument is retry delay in ms.
40
40
* "connect" - emitted when the client connected and auth passed (if username and password provided), first argument is an object with host and port of the Taranool server.
41
+
* "change_host" - emitted when `nonWritableHostPolicy` option is set and write error occurs, first argument is the text of error which provoked the host to be changed.
41
42
42
43
| Param | Type | Default | Description |
43
44
| --- | --- | --- | --- |
44
45
|[port]| <code>number</code> \| <code>string</code> \| <code>Object</code> | <code>3301</code> | Port of the Tarantool server, or a URI string (see the examples in [tarantool configuration doc](https://tarantool.org/en/doc/reference/configuration/index.html#uri)), or the `options` object(see the third argument). |
45
46
|[host]| <code>string</code> \| <code>Object</code> | <code>"localhost"</code> | Host of the Tarantool server, when the first argument is a URL string, this argument is an object represents the options. |
46
-
|[options]| <code>Object</code> || Other options. |
47
+
|[path]| <code>string</code> \| <code>Object</code> | <code>null</code> | Unix socket path of the Tarantool server. |
48
+
|[options]| <code>Object</code> || Other options, including all from [net.createConnection](https://nodejs.org/api/net.html#netcreateconnection). |
47
49
|[options.port]| <code>number</code> | <code>6379</code> | Port of the Tarantool server. |
48
50
|[options.host]| <code>string</code> | <code>"localhost"</code> | Host of the Tarantool server. |
49
51
|[options.username]| <code>string</code> | <code>null</code> | If set, client will authenticate with the value of this option when connected. |
50
52
|[options.password]| <code>string</code> | <code>null</code> | If set, client will authenticate with the value of this option when connected. |
51
53
|[options.timeout]| <code>number</code> | <code>0</code> | The milliseconds before a timeout occurs during the initial connection to the Tarantool server. |
54
+
|[options.tls]| <code>Object</code> | <code>null</code> | If specified, forces to use `tls` module instead of the default `net`. In object properties you can specify any TLS-related options, e.g. from the [tls.createSecureContext()](https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions)|
|[options.noDelay]| <code>boolean</code> | <code>true</code> | Disables the use of Nagle's algorithm (recommended). |
52
57
|[options.lazyConnect]| <code>boolean</code> | <code>false</code> | By default, When a new `Tarantool` instance is created, it will connect to Tarantool server automatically. If you want to keep disconnected util a command is called, you can pass the `lazyConnect` option to the constructor. |
58
+
|[options.nonWritableHostPolicy]| <code>string</code> | <code>null</code> | What to do when Tarantool server rejects write operation, e.g. because of `box.cfg.read_only` set to `true` or during snapshot fetching. <br /> Possible values are: <br /> - `null`: just rejects Promise with an error <br /> - `changeHost`: disconnect from the current host and connect to the next from `reserveHosts`. Pending Promise will be rejected. <br /> - `changeAndRetry`: same as `changeHost`, but after reconnecting tries to run the command again in order to fullfil the Promise |
59
+
|[options.maxRetriesPerRequest]| <code>number</code> | <code>5</code> | Number of attempts to find the alive host if `nonWritableHostPolicy` is not null. |
60
+
|[options.enableOfflineQueue]| <code>boolean</code> | <code>true</code> | By default, if there is no active connection to the Tarantool server, commands are added to a queue and are executed once the connection is "ready", meaning the connection to the Tarantool server has been established and auth passed (`connect` event is also executed at this moment). If this option is false, when execute the command when the connection isn't ready, an error will be returned. |
53
61
|[options.reserveHosts]| <code>array</code> |[]| Array of [strings](https://tarantool.org/en/doc/reference/configuration/index.html?highlight=uri#uri) - reserve hosts. Client will try to connect to hosts from this array after loosing connection with current host and will do it cyclically. See example below.|
54
62
|[options.beforeReserve]| <code>number</code> | <code>2</code> | Number of attempts to reconnect before connect to next host from the <code>reserveHosts</code> |
55
63
|[options.retryStrategy]| <code>function</code> || See below |
@@ -107,7 +115,7 @@ will be lost forever if the user doesn't call `tarantool.connect()` manually.
107
115
## Usage example
108
116
109
117
We use TarantoolConnection instance and connect before other operations. Methods call return promise(https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Promise). Available methods with some testing: select, update, replace, insert, delete, auth, destroy.
110
-
```
118
+
```javascript
111
119
var TarantoolConnection =require('tarantool-driver');
112
120
var conn =newTarantoolConnection('notguest:sesame@mail.ru:3301');
You can use any implementation that can be duck typing with next interface:
125
133
126
-
```
127
-
134
+
```Javascript
128
135
//msgpack implementation example
129
136
/*
130
137
@interface
@@ -155,6 +162,24 @@ Resolve if connected. Or reject if not.
155
162
156
163
Auth with using [chap-sha1](http://tarantool.org/doc/book/box/box_space.html). About authenthication more here: [authentication](http://tarantool.org/doc/book/box/authentication.html)
157
164
165
+
### tarantool.packUuid(uuid: String)
166
+
167
+
**Method for converting [UUID values](https://www.tarantool.io/ru/doc/latest/concepts/data_model/value_store/#uuid) to Tarantool-compatible format.**
168
+
169
+
If passing UUID without converion via this method, server will accept it as simple String.
**Method for converting Numbers (Float or Integer) to Tarantool [Decimal](https://www.tarantool.io/ru/doc/latest/concepts/data_model/value_store/#decimal) type.**
174
+
175
+
If passing number without converion via this method, server will accept it as Integer or Double (for JS Float type).
**Method for safely passing numbers up to int64 to bind params**
180
+
181
+
Otherwise msgpack will encode anything bigger than int32 as a double number.
182
+
158
183
### tarantool.select(spaceId: Number or String, indexId: Number or String, limit: Number, offset: Number, iterator: Iterator, key: tuple) ⇒ <code>Promise</code>
@@ -163,13 +188,28 @@ It's just select. Promise resolve array of tuples.
163
188
164
189
Some examples:
165
190
166
-
```
191
+
```Javascript
167
192
conn.select(512, 0, 1, 0, 'eq', [50]);
168
193
//same as
169
194
conn.select('test', 'primary', 1, 0, 'eq', [50]);
170
195
```
171
196
172
-
You can use space name or index name instead of id, but it will some requests for get this metadata. That information actual for delete, replace, insert, update too.
197
+
You can use space name or index name instead of id, but this way some requests will be made to get and cache metadata. This stored information will be actual for delete, replace, insert, update too.
198
+
199
+
For tests, we will create a Space named 'users' on the Tarantool server-side, where the 'id' index is of UUID type:
@@ -299,10 +357,24 @@ It's ok you can do whatever you need. I add log options for some technical infor
299
357
300
358
## Changelog
301
359
360
+
### 3.1.0
361
+
362
+
- Added 3 new msgpack extensions: UUID, Datetime, Decimal.
363
+
- Connection object now accepts all options of `net.createConnection()`, including Unix socket path.
364
+
- New `nonWritableHostPolicy` and related options, which improves a high availability capabilities without any 3rd parties.
365
+
- Ability to disable the offline queue.
366
+
- Fixed [bug with int32](https://github.com/tarantool/node-tarantool-driver/issues/48) numbers when it was encoded as floating. Use method `packInteger()` to solve this.
367
+
-`selectCb()` now also accepts `spaceId` and `indexId` as their String names, not only their IDs.
368
+
- Some performance improvements by caching internal values.
369
+
- TLS (SSL) support.
370
+
- New `pipeline()`+`exec()` methods kindly borrowed from the [ioredis](https://github.com/redis/ioredis?tab=readme-ov-file#pipelining), which lets you to queue some commands in memory and then send them simultaneously to the server in a single (or several, if request body is too big) network call(s). Thanks to the Tarantool, which [made this possible](https://www.tarantool.io/en/doc/latest/dev_guide/internals/iproto/format/#packet-structure).
371
+
This way the performance is significantly improved by 500-1600% - you can check it yourself by running `npm run benchmark-read` or `npm run benchmark-write`.
372
+
Note that this feature doesn't replaces the Transaction model, which has some level of isolation.
373
+
- Changed `const` declaration to `var` in order to support old Node.JS versions.
374
+
302
375
### 3.0.7
303
376
304
-
Fix in header decoding to support latest Tarantool versions.
305
-
Update to tests to support latest Tarantool versions.
377
+
Fix in header decoding to support latest Tarantool versions. Update to tests to support latest Tarantool versions.
306
378
307
379
### 3.0.6
308
380
@@ -348,4 +420,7 @@ Key is now can be just a number.
0 commit comments