Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
47 changes: 47 additions & 0 deletions doc/7/controllers/ms/mexecute/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
code: true
type: page
title: mexecute
---

# mexecute

Allows the execution of multiple commands or 'actions' in a single step.

It creates a redis **transaction** block and **executes** it immediately, all actions will be executed sequentially and as a single atomic and isolated operation.

[[_Redis documentation_]](https://redis.io/topics/transactions)

::: warning
Only already supported actions can be executed using **mexecute**.
:::

## Arguments

```js
mexecute(actions, [options]);
```

<br/>

| Arguments | Type | Description |
| --------- | ------------------- | ------------------------------ |
| `actions` | <pre>object[]</pre> | List of actions to execute |
| `options` | <pre>object</pre> | Optional query arguments |

### actions

The `actions` argument is an array of objects. Each object describes an action to be executed, using the following properties:

| Property | Type | Description |
| -------- | ----------------- | ----------- |
| `action` | <pre>string</pre> | Action name |
| `args` | <pre>object</pre> | Arguments |

## Resolve

Returns an array of error & result pairs for each executed action, in order.

## Usage

<<< ./snippets/mexecute.js
13 changes: 13 additions & 0 deletions doc/7/controllers/ms/mexecute/snippets/mexecute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
try {

const actions = [
{ 'action': 'set', 'args': { '_id': 'list:a', 'body': { 'value': 1, 'ex': 100, 'nx': true } } },
{ 'action': 'get', 'args': { '_id': 'list:a' } },
{ 'action': 'del', 'args': { 'body': { 'keys': ['list:a'] } } }];

// Prints: "[ [ null, 'OK' ], [ null, '1' ], [ null, 1 ] ]"
console.log(await kuzzle.ms.mexecute(actions));

} catch (error) {
console.error(error.message);
}
9 changes: 9 additions & 0 deletions doc/7/controllers/ms/mexecute/snippets/mexecute.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: ms#mexecute
description: Executes multiple commands in a single step
hooks:
before: curl -X POST kuzzle:7512/ms/_flushdb
after:
template: default
expected: "\\[ \\[ null, 'OK' ], \\[ null, '1' ], \\[ null, 1 ] ]"
sdk: js
version: 7
Loading