Package Exports
- node-redis-script
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-redis-script) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
redis-script
Easily run redis scripts from Node.
Requirements
- node-redis v0.10+ or ioredis
- Redis
v2.6or above - Node 10+
Install
npm install node-redis-scriptUsage
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