🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

redisinsight-plugin-sdk

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redisinsight-plugin-sdk

Redis API for creating packages for Redis v.2 application

1.1.0
latest
Source
npm
Version published
Weekly downloads
159
15.22%
Maintainers
2
Weekly downloads
 
Created
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

redis

FAQs

Package last updated on 14 Feb 2023

Did you know?

Socket

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