# node-redis-script

> Easily use redis scripts in Node

Latest version **2.0.1** (published 2021-04-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-redis-script
pnpm add node-redis-script
yarn add node-redis-script
bun add node-redis-script
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-04-02 |
| First published | 2021-02-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Geoff Wagstaff |
| Maintainers | thedeveloper |
| Keywords | redis, script, node.js, manager |

## Links

- npm: https://www.npmjs.com/package/node-redis-script
- Repository: https://github.com/thedeveloper/scripty
- Issues: https://github.com/thedeveloper/scripty/issues
- npm.io page: https://npm.io/package/node-redis-script

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-04-02
- 2.0.0 — 2021-04-02
- 1.0.3 — 2021-02-25
- 1.0.2 — 2021-02-25

## README

redis-script
=======

Easily run redis scripts from Node.

# Requirements

* [node-redis](https://github.com/NodeRedis/node-redis) v0.10+ or [ioredis](https://github.com/luin/ioredis)
* Redis `v2.6` or above
* Node 10+

# Install

    npm install node-redis-script

# Usage

```javascript
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
```js
const opts = {
  // you can use either node-redis or ioredis client
  redis, // node-redis client
  ioredis // ioredis client
};
```

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

---
_Source: https://npm.io/package/node-redis-script · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
