# redisinsight-plugin-sdk

> Redis API for creating packages for Redis v.2 application

Latest version **1.1.0** (published 2023-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install redisinsight-plugin-sdk
pnpm add redisinsight-plugin-sdk
yarn add redisinsight-plugin-sdk
bun add redisinsight-plugin-sdk
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-02-14 |
| First published | 2022-02-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8929 |
| Author | Redis |
| Maintainers | roman.sergeenko, viktarstarastsenka |
| Keywords | redis, redis-gui |

## Links

- npm: https://www.npmjs.com/package/redisinsight-plugin-sdk
- Repository: https://github.com/RedisInsight/RedisInsight.git#main
- Homepage: https://github.com/RedisInsight/RedisInsight/tree/main#readme
- Issues: https://github.com/RedisInsight/RedisInsight/issues
- npm.io page: https://npm.io/package/redisinsight-plugin-sdk

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2023-02-14
- 1.0.1 — 2022-03-18
- 1.0.0 — 2022-02-18

## README

# RedisInsight-plugin-sdk

The high-level API for communication between RedisInsight
plugin and RedisInsight application.

## Usage
```
npm install redisinsight-plugin-sdk
or
yarn add redisinsight-plugin-sdk
```

## Available methods

### setHeaderText(text)
Sets any custom text to the header of the command result

**Parameters:**

* `text` **{String}**

**Example:**

```js
import { setHeaderText } from 'redisinsight-plugin-sdk';
setHeaderText('Matched: 10')
```

### executeRedisCommand(command)

Executes a Redis command _(currently, only read-only commands are supported)_.

**Parameters:**

* `command` **{String}** - command to execute

**Returns:**
* `Promise<[{ response, status }]>`

```js
/**
 * @async
 * @param {String} command
 * @returns {Promise.<[{ response, status }]>}
 * @throws {Error}
 */
```

**Example:**

```js
import { executeRedisCommand } from 'redisinsight-plugin-sdk';
try {
  const result = await executeRedisCommand('GET foo');
  const [{ response, status }] = result;
  if (status === 'success') {
    // Do smth
  }
} catch (e) {
    console.error(e);
}
```

### getState()

Returns saved state for the command visualization.

Throw an error if the state has not been saved.

**Parameters:**

* `state` **{any}** - any data to save

**Returns:**
* `Promise<any>`

```js
/**
 * @async
 * @returns {Promise.<any>} state
 * @throws {Error}
 */
```

**Example:**

```js
import { getState } from 'redisinsight-plugin-sdk';
try {
  const result = await getState();
} catch (e) {
    console.error(e);
}
```


### setState(state)

Save the state for the command visualization.

**Returns:**
* `Promise<any>`

```js
/**
 * @async
 * @param {any} state
 * @returns {Promise.<any>} state
 * @throws {Error}
 */
```

**Example:**

```js
import { setState } from 'redisinsight-plugin-sdk';
try {
  await setState({ a: 1, b: 2 });
} catch (e) {
    console.error(e);
}
```

### formatRedisReply(response, command)

Util function to parse Redis response

Returns string with parsed cli-like response

**Returns:**
* `Promise<string>`

```js
/**
 * @async
 * @param {any} response
 * @param {String} command
 * @returns {Promise.<string>} data
 * @throws {Error}
 */
```

**Example:**

```js
import { formatRedisReply } from 'redisinsight-plugin-sdk';

try {
  const parsedReply = await formatRedisReply(data[0].response, command);
  
  /*
    parsedReply:
    
    1) 1) "COUNT(a)"
    2) 1) 1) "0"
    3) 1) "Cached execution: 1"
       2) "Query internal execution time: 3.134125 milliseconds"
   */
} catch (e) {
    console.error(e);
}
```

---
_Source: https://npm.io/package/redisinsight-plugin-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
