Socket
Socket
Sign inDemoInstall

redisinsight-plugin-sdk

Package Overview
Dependencies
0
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redisinsight-plugin-sdk

Redis API for creating packages for Redis v.2 application


Version published
Maintainers
2
Install size
7.23 kB
Created

Readme

Source

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:

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 }]>
/**
 * @async
 * @param {String} command
 * @returns {Promise.<[{ response, status }]>}
 * @throws {Error}
 */

Example:

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>
/**
 * @async
 * @returns {Promise.<any>} state
 * @throws {Error}
 */

Example:

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>
/**
 * @async
 * @param {any} state
 * @returns {Promise.<any>} state
 * @throws {Error}
 */

Example:

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>
/**
 * @async
 * @param {any} response
 * @param {String} command
 * @returns {Promise.<string>} data
 * @throws {Error}
 */

Example:

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);
}

Keywords

FAQs

Last updated on 14 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc