Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autopipeling for buffer function + added built in commands #1231

Merged
merged 8 commits into from
May 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 82 additions & 24 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Redis ⇐ <code>[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)</code>

**Kind**: global class
**Kind**: global class
**Extends**: <code>[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)</code>, [<code>Commander</code>](#Commander)

- [Redis](#Redis) ⇐ <code>[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)</code>
Expand All @@ -25,6 +25,7 @@
- [.duplicate()](#Redis+duplicate)
- [.monitor([callback])](#Redis+monitor)
- [.getBuiltinCommands()](#Commander+getBuiltinCommands) ⇒ <code>Array.&lt;string&gt;</code>
- [.addBuiltinCommand(commandName)](#Commander+createBuiltinCommand)
- [.createBuiltinCommand(commandName)](#Commander+createBuiltinCommand) ⇒ <code>object</code>
- [.defineCommand(name, definition)](#Commander+defineCommand)
- _static_
Expand Down Expand Up @@ -98,7 +99,8 @@ unless `lazyConnect: true` is passed.
When calling this method manually, a Promise is returned, which will
be resolved when the connection status is ready.

**Kind**: instance method of [<code>Redis</code>](#Redis)
**Kind**: instance method of [<code>Redis</code>](#Redis)

**Access**: public

| Param | Type |
Expand Down Expand Up @@ -132,8 +134,9 @@ Disconnect from Redis.

Create a new instance with the same options as the current one.

**Kind**: instance method of [<code>Redis</code>](#Redis)
**Access**: public
**Kind**: instance method of [<code>Redis</code>](#Redis)
**Access**: public

**Example**

```js
Expand All @@ -151,7 +154,8 @@ This command will create a new connection to Redis and send a
MONITOR command via the new connection in order to avoid disturbing
the current connection.

**Kind**: instance method of [<code>Redis</code>](#Redis)
**Kind**: instance method of [<code>Redis</code>](#Redis)

**Access**: public

| Param | Type | Description |
Expand Down Expand Up @@ -183,17 +187,33 @@ redis.monitor().then(function (monitor) {

Return supported builtin commands

**Kind**: instance method of [<code>Redis</code>](#Redis)
**Returns**: <code>Array.&lt;string&gt;</code> - command list
**Kind**: instance method of [<code>Redis</code>](#Redis)
**Returns**: <code>Array.&lt;string&gt;</code> - command list
**Access**: public
<a name="Commander+addBuiltinCommand"></a>

### redis.addBuiltinCommand(commandName) ⇒ <code>object</code>

Adds a builtin command

**Kind**: instance method of [<code>Redis</code>](#Redis)
**Returns**: <code>void</code>
**Access**: public

| Param | Type | Description |
| ----------- | ------------------- | ------------ |
| commandName | <code>string</code> | command name |


<a name="Commander+createBuiltinCommand"></a>

### redis.createBuiltinCommand(commandName) ⇒ <code>object</code>

Create a builtin command

**Kind**: instance method of [<code>Redis</code>](#Redis)
**Returns**: <code>object</code> - functions
**Kind**: instance method of [<code>Redis</code>](#Redis)
**Returns**: <code>object</code> - functions

**Access**: public

| Param | Type | Description |
Expand Down Expand Up @@ -228,7 +248,7 @@ Create a Redis instance

## Cluster ⇐ <code>[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)</code>

**Kind**: global class
**Kind**: global class
**Extends**: <code>[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)</code>, [<code>Commander</code>](#Commander)

- [Cluster](#Cluster) ⇐ <code>[EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)</code>
Expand All @@ -238,6 +258,7 @@ Create a Redis instance
- [.quit([callback])](#Cluster+quit) ⇒ <code>Promise</code>
- [.nodes([role])](#Cluster+nodes) ⇒ [<code>Array.&lt;Redis&gt;</code>](#Redis)
- [.getBuiltinCommands()](#Commander+getBuiltinCommands) ⇒ <code>Array.&lt;string&gt;</code>
- [.addBuiltinCommand(commandName)](#Commander+createBuiltinCommand)
- [.createBuiltinCommand(commandName)](#Commander+createBuiltinCommand) ⇒ <code>object</code>
- [.defineCommand(name, definition)](#Commander+defineCommand)
- _[.sendCommand()](#Commander+sendCommand)_
Expand Down Expand Up @@ -279,7 +300,8 @@ Connect to a cluster

Disconnect from every node in the cluster.

**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Kind**: instance method of [<code>Cluster</code>](#Cluster)

**Access**: public

| Param | Type |
Expand All @@ -292,8 +314,9 @@ Disconnect from every node in the cluster.

Quit the cluster gracefully.

**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>Promise</code> - return 'OK' if successfully
**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>Promise</code> - return 'OK' if successfully

**Access**: public

| Param | Type |
Expand All @@ -306,8 +329,9 @@ Quit the cluster gracefully.

Get nodes with the specified role

**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: [<code>Array.&lt;Redis&gt;</code>](#Redis) - array of nodes
**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: [<code>Array.&lt;Redis&gt;</code>](#Redis) - array of nodes

**Access**: public

| Param | Type | Default | Description |
Expand All @@ -320,17 +344,33 @@ Get nodes with the specified role

Return supported builtin commands

**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>Array.&lt;string&gt;</code> - command list
**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>Array.&lt;string&gt;</code> - command list
**Access**: public
<a name="Commander+addBuiltinCommand"></a>

### cluster.addBuiltinCommand(commandName) ⇒ <code>object</code>

Adds a builtin command

**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>void</code>
**Access**: public

| Param | Type | Description |
| ----------- | ------------------- | ------------ |
| commandName | <code>string</code> | command name |


<a name="Commander+createBuiltinCommand"></a>

### cluster.createBuiltinCommand(commandName) ⇒ <code>object</code>

Create a builtin command

**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>object</code> - functions
**Kind**: instance method of [<code>Cluster</code>](#Cluster)
**Returns**: <code>object</code> - functions

**Access**: public

| Param | Type | Description |
Expand Down Expand Up @@ -370,6 +410,7 @@ Send a command
- [Commander](#Commander)
- [new Commander()](#new_Commander_new)
- [.getBuiltinCommands()](#Commander+getBuiltinCommands) ⇒ <code>Array.&lt;string&gt;</code>
- [.addBuiltinCommand(commandName)](#Commander+createBuiltinCommand)
- [.createBuiltinCommand(commandName)](#Commander+createBuiltinCommand) ⇒ <code>object</code>
- [.defineCommand(name, definition)](#Commander+defineCommand)
- _[.sendCommand()](#Commander+sendCommand)_
Expand All @@ -392,17 +433,33 @@ This is the base class of Redis, Redis.Cluster and Pipeline

Return supported builtin commands

**Kind**: instance method of [<code>Commander</code>](#Commander)
**Returns**: <code>Array.&lt;string&gt;</code> - command list
**Kind**: instance method of [<code>Commander</code>](#Commander)
**Returns**: <code>Array.&lt;string&gt;</code> - command list
**Access**: public
<a name="Commander+addBuiltinCommand"></a>

### commander.addBuiltinCommand(commandName) ⇒ <code>object</code>

Adds a builtin command

**Kind**: instance method of [<code>Commander</code>](#Commander)
**Returns**: <code>void</code>
**Access**: public

| Param | Type | Description |
| ----------- | ------------------- | ------------ |
| commandName | <code>string</code> | command name |


<a name="Commander+createBuiltinCommand"></a>

### commander.createBuiltinCommand(commandName) ⇒ <code>object</code>

Create a builtin command

**Kind**: instance method of [<code>Commander</code>](#Commander)
**Returns**: <code>object</code> - functions
**Kind**: instance method of [<code>Commander</code>](#Commander)
**Returns**: <code>object</code> - functions

**Access**: public

| Param | Type | Description |
Expand Down Expand Up @@ -430,5 +487,6 @@ Define a custom command using lua script

Send a command

**Kind**: instance abstract method of [<code>Commander</code>](#Commander)
**Kind**: instance abstract method of [<code>Commander</code>](#Commander)

**Access**: public
21 changes: 15 additions & 6 deletions lib/autoPipelining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ function executeAutoPipeline(client, slotKey: string) {
});
}

export function shouldUseAutoPipelining(client, commandName: string): boolean {
export function shouldUseAutoPipelining(
client,
functionName: string,
commandName: string
): boolean {
return (
functionName &&
adamnoakes marked this conversation as resolved.
Show resolved Hide resolved
client.options.enableAutoPipelining &&
!client.isPipeline &&
!notAllowedAutoPipelineCommands.includes(commandName) &&
Expand All @@ -84,6 +89,7 @@ export function shouldUseAutoPipelining(client, commandName: string): boolean {

export function executeWithAutoPipelining(
client,
functionName: string,
commandName: string,
args: string[],
callback
Expand All @@ -99,10 +105,13 @@ export function executeWithAutoPipelining(
return;
}

executeWithAutoPipelining(client, commandName, args, callback).then(
resolve,
reject
);
executeWithAutoPipelining(
client,
functionName,
commandName,
args,
callback
).then(resolve, reject);
});
});
}
Expand Down Expand Up @@ -143,7 +152,7 @@ export function executeWithAutoPipelining(
resolve(value);
});

pipeline[commandName](...args);
pipeline[functionName](...args);
});

return asCallback(autoPipelinePromise, callback);
Expand Down
Loading