node-redis-script

2.0.1 • Public • Published

redis-script

Easily run redis scripts from Node.

Requirements

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.16,031latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.16,031
2.0.01
1.0.31
1.0.21

Package Sidebar

Install

npm i node-redis-script

Weekly Downloads

5,827

Version

2.0.1

License

MIT

Unpacked Size

6.62 kB

Total Files

9

Last publish

Collaborators

  • thedeveloper