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

handy-redis

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

handy-redis

A wrapper around node_redis with Promise and TypeScript support.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
decreased by-80.96%
Maintainers
1
Weekly downloads
 
Created
Source

handy-redis

A wrapper around node_redis with Promise and TypeScript support.

Build Status Coverage Status npm version

Why

node_redis doesn't support Promises out-of-the-box - you have to use bluebird's promisifyAll, which has the side effect of removing all TypeScript/intellisense support from the package.

This package is a wrapper around node_redis and exclusively uses Promises It publishes TypeScript types generated from the official redis documentation and examples, so it's much easier to know what parameters a command expects.

Usage

npm install --save handy-redis

ES6/TypeScript:

import { createHandyClient } from 'handy-redis';

(async function() {
    const client = createHandyClient();
    // or, call createHandyClient(opts) using opts for https://npmjs.com/package/redis
    // or, call createHandyClient(oldClient) where oldClient is an existing node_redis client.

    await client.set('foo', 'bar');
    const foo = await client.get('foo');
    console.log(foo);
})();

Vanilla JS:

const handyRedis = require('handy-redis');

const client = handyRedis.createHandyClient();

client
    .set('foo', 'bar')
    .then(() => client.get('foo'))
    .then(foo => console.log(foo));

The package is published with TypeScript types, with the redis documentation and response type attached to each command:

Examples

See the snapshot tests for tons of usage examples (look at the .md files).

Multi

Most members of node_redis's multi type don't need to be promisified, because they execute synchronously. Only exec is async. To use a promisified version of that, use execMulti:

import { createHandyClient } from 'handy-redis';

(async function() {
    const client = createHandyClient();

    const multi = client.multi().set("z:foo", "987").keys("z:*").get("z:foo");

    const result = await client.execMulti(multi);

    console.log(result); // ["OK", ["z:foo"], "987"]
})();

execMulti is generic, so in TypeScript you can use something like const strings = await client.execMulti<string>(multi) if you know all results will be strings. Otherwise the type will default to {}.

Development

Most of the package is generated by running sample commands from the redis documentation repo.

git clone https://github.com/mmkal/handy-redis --recursive
cd handy-redis
npm install
npm test

npm test triggers npm run build before running the tests - and the build script generates the client before using TypeScript to compile it.

If you cloned without --recursive you'll need to run git submodule update --init to get the redis-doc repo locally.

Testing

If a snapshot test fails, it's possible it just needs to be updated. Make sure your git status is clean and run npm test -- -u.

Keywords

FAQs

Package last updated on 13 Dec 2017

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