Giter Site home page Giter Site logo

node-redis-script's Introduction

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

node-redis-script's People

Contributors

thedeveloper avatar behrad avatar

Watchers

 avatar James Cloos avatar

node-redis-script's Issues

Switch to IORedis instead of promisify

@TheDeveloper I use the excellent warlock which relies on this library (or more accurately the deprecated scripty library) and I'd like to move away from node-redis since it doesn't support promises.

I can see that this library uses promisify and I think that it should directly use IORedis instead. That way, we could easily change the warlock client as well and have a cleaner code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.