|
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. |
5 | 11 |
|
6 | 12 | ## Using
|
7 | 13 |
|
8 | 14 | ```cli
|
9 | 15 | npm install --save handy-redis
|
10 | 16 | ```
|
11 | 17 |
|
| 18 | +ES6/TypeScript: |
12 | 19 | ```JavaScript
|
13 |
| -import { createClient } from 'handy-redis'; |
| 20 | +import { createHandyClient } from 'handy-redis'; |
14 | 21 |
|
15 | 22 | (async function() {
|
16 |
| - const client = createClient(); // or call createClient(opts) using opts for https://npmjs.com/package/redis |
| 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. |
17 | 26 |
|
18 | 27 | await client.set('foo', 'bar');
|
19 | 28 | const foo = await client.get('foo');
|
| 29 | + console.log(foo); |
20 | 30 | })();
|
21 | 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