Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-redis-script

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-redis-script

Easily use redis scripts in Node

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.1K
increased by0.56%
Maintainers
1
Weekly downloads
 
Created
Source

redis-script

Easily run redis scripts from Node.

Requirements

  • node-redis v0.10+ or ioredis
  • Redis v2.6 or above
  • Node 10+

Install

npm install node-redis-script

Usage

const redis = require('redis').createClient();
const { createScript } = require('node-redis-script');

const incrbyExSrc = `
  local current
  current = redis.call('incrby',KEYS[1],ARGV[1])
  redis.call('expire',KEYS[1],ARGV[2]);
  return current
`;

// give it a redis client and script source
const opts = { redis }; // or { ioredis } for ioredis
const incrbyEx = createScript(opts, incrbyExSrc);
// you get back a function that runs your script with given args
// redis requires you to tell it how many keys to expect
const numKeys = 1;
const key = 'test';
const incr = 1;
const ex = 10;
const result = await incrbyEx(numKeys, key, incr, ex);
// Should print 1
console.log(result);

Options

const opts = {
  // you can use either node-redis or ioredis client
  redis, // node-redis client
  ioredis // ioredis client
};

Test

# install docker & docker-compose for local redis setup
npm test

Keywords

FAQs

Package last updated on 02 Apr 2021

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc