|
1 | 1 | # handy-redis
|
2 |
| -A wrapper around node_redis with Promise and TypeScript support. |
| 2 | +A wrapper around [node_redis](https://npmjs.com/package/redis) with Promise and TypeScript support. |
3 | 3 |
|
4 |
| -[](https://travis-ci.org/mmkal/handy-redis) |
| 4 | +[](https://travis-ci.org/mmkal/handy-redis) |
| 5 | + |
| 6 | +## Why |
| 7 | + |
| 8 | +[node_redis](https://npmjs.com/package/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. |
| 9 | + |
| 10 | +This package exclusively uses Promises, and the TypeScript types are generated from the official redis documentation and examples, so it's much easier to know what parameters a command expects. |
| 11 | + |
| 12 | +## Using |
| 13 | + |
| 14 | +```cli |
| 15 | +npm install --save handy-redis |
| 16 | +``` |
| 17 | + |
| 18 | +ES6/TypeScript: |
| 19 | +```JavaScript |
| 20 | +import { createHandyClient } from 'handy-redis'; |
| 21 | + |
| 22 | +(async function() { |
| 23 | + const client = createHandyClient(); |
| 24 | + // or, call createHandyClient(opts) using opts for https://npmjs.com/package/redis |
| 25 | + // or, call createHandyClient(oldClient) where oldClient is an existing node_redis client. |
| 26 | + |
| 27 | + await client.set('foo', 'bar'); |
| 28 | + const foo = await client.get('foo'); |
| 29 | + console.log(foo); |
| 30 | +})(); |
| 31 | +``` |
| 32 | + |
| 33 | +Vanilla JS: |
| 34 | +```JavaScript |
| 35 | +const handyRedis = require('handy-redis'); |
| 36 | + |
| 37 | +const client = handyRedis.createHandyClient(); |
| 38 | + |
| 39 | +client |
| 40 | + .set('foo', 'bar') |
| 41 | + .then(() => client.get('foo')) |
| 42 | + .then(foo => console.log(foo)); |
| 43 | +``` |
| 44 | + |
| 45 | +The package is published with TypeScript types, with the redis documentation and response type attached to each command: |
| 46 | + |
| 47 | + |
| 48 | +## Development |
| 49 | + |
| 50 | +Most of the package is generated by running sample commands from the redis documentation repo. |
| 51 | + |
| 52 | +```cli |
| 53 | +git clone https://github.com/mmkal/handy-redis --recursive |
| 54 | +npm install |
| 55 | +npm test |
| 56 | +``` |
| 57 | + |
| 58 | +`npm test` triggers `npm run build` before running the tests - and the `build` script generates the client before using TypeScript to compile it. |
| 59 | + |
| 60 | +If you cloned without `--recursive` you'll need to run `git submodule update --init` to get the redis-doc repo locally. |
0 commit comments