redis

A high performance Redis client.

tarball contains the wrong files
Last updated 4 years ago by leibale .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install redis 
SYNC missed versions from official npm registry.

:warning: Version 4 is still under development and isn't ready for production use. Use at your own risk.


Node Redis

A high performance Node.js Redis client.


NPM downloads NPM version Coverage Status


Installation

npm install redis@next

Usage

Basic Example

(async () => {
    const client = require('redis').createClient();

    client.on('error', (err) => console.log('Redis Client Error', err));
    
    await client.connect();

    await client.set('key', 'value');
    const value = await client.get('key');
})();

Redis Commands

There is built-in support for all of the out-of-the-box Redis commands. They are exposed using the raw Redis command names (HGET, HSET, etc.) and a friendlier camel-cased version (hGet, hSet, etc.).

// raw Redis commands
await client.SET('key', 'value');
await client.GET('key');

// friendly JavaScript commands
await client.hSet('key', 'field', 'value');
await client.hGetAll('key');

Modifiers to commands are specified using a JavaScript object:

await client.set('key', 'value', {
    EX: 10,
    NX: true
});

Replies will be transformed to useful data structures:

await client.hGetAll('key'); // { key1: 'value1', key2: 'value2' }
await client.hKeys('key'); // ['key1', 'key2']

Unsupported Redis Commands

If you want to run commands and arguments that Node Redis doesn't know about (yet!) you can use .sendCommand:

await client.sendCommand(['SET', 'key', 'value', 'NX']); // 'OK'

await client.sendCommand(['HGETALL', 'key']); // ['key1', 'field1', 'key2', 'field2']

Blocking Commands

Any command can be run on a new connection by specifying the duplicateConnection option. The newly created connection is closed when command's Promise is fulfilled.

This pattern works especially well for blocking commands—such as BLPOP and BRPOPLPUSH:

const blPopPromise = client.blPop(
    client.commandOptions({ duplicateConnection: true }),
    'key'
);

await client.lPush('key', ['1', '2']);

await blPopPromise; // '2'

Pub/Sub

Subscribing to a channel requires a dedicated Redis connection and is easily handled using events.

await subscriber.subscribe('channel', message => {
    console.log(message); // 'message'
});

await subscriber.pSubscribe('channe*', (message, channel) => {
    console.log(message, channel); // 'message', 'channel'
});

await publisher.publish('channel', 'message');

Lua Scripts

You can define Lua scripts to create efficient custom commands:

(async () => {
    const client = require('redis').createClient({
        scripts: {
            add: require('redis/lua-script').defineScript({
                NUMBER_OF_KEYS: 1,
                SCRIPT:
                    'local val = redis.pcall("GET", KEYS[1]);' +
                    'return val + ARGV[1];',
                transformArguments(key: string, toAdd: number): Array<string> {
                    return [key, number.toString()];
                },
                transformReply(reply: number): number {
                    return reply;
                }
            })
        }
    });

    await client.connect();

    await client.set('key', '1');
    await client.add('key', 2); // 3
})();

Contributing

If you'd like to contribute, check out the contributing guide.

License

This repository is licensed under the "MIT" license. See LICENSE.

Current Tags

  • 4.7.0                                ...           latest (5 months ago)
  • 5.0.0-next.5                                ...           next (2 months ago)

156 Versions

  • 5.0.0-next.5                                ...           2 months ago
  • 4.7.0                                ...           5 months ago
  • 4.6.15                                ...           6 months ago
  • 4.6.14                                ...           7 months ago
  • 4.6.13                                ...           a year ago
  • 4.6.12                                ...           a year ago
  • 4.6.11                                ...           a year ago
  • 5.0.0-next.4                                ...           a year ago
  • 5.0.0-next.3                                ...           a year ago
  • 5.0.0-next.2                                ...           a year ago
  • 5.0.0-next.1                                ...           a year ago
  • 4.6.10                                ...           a year ago
  • 4.6.9                                ...           a year ago
  • 4.6.8                                ...           a year ago
  • 4.6.7                                ...           2 years ago
  • 4.6.6                                ...           2 years ago
  • 4.6.5                                ...           2 years ago
  • 4.6.4                                ...           2 years ago
  • 4.6.3                                ...           2 years ago
  • 4.6.2                                ...           2 years ago
  • 4.6.1                                ...           2 years ago
  • 4.6.0                                ...           2 years ago
  • 4.5.1                                ...           2 years ago
  • 4.5.0                                ...           2 years ago
  • 4.4.0                                ...           2 years ago
  • 4.3.1                                ...           2 years ago
  • 4.3.0                                ...           2 years ago
  • 4.2.0                                ...           2 years ago
  • 4.1.1                                ...           2 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.6                                ...           3 years ago
  • 4.0.5 [deprecated]           ...           3 years ago
  • 4.0.4                                ...           3 years ago
  • 4.0.3                                ...           3 years ago
  • 4.0.2                                ...           3 years ago
  • 4.0.1                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 4.0.0-rc.4                                ...           3 years ago
  • 4.0.0-rc.3                                ...           3 years ago
  • 4.0.0-rc.2                                ...           3 years ago
  • 4.0.0-rc.1                                ...           3 years ago
  • 4.0.0-rc.0                                ...           3 years ago
  • 4.0.0-next.7                                ...           3 years ago
  • 4.0.0-next.6                                ...           3 years ago
  • 4.0.0-next.5                                ...           3 years ago
  • 4.0.0-next.4                                ...           3 years ago
  • 4.0.0-next.3                                ...           4 years ago
  • 4.0.0-next.2                                ...           4 years ago
  • 4.0.0-next.1 [deprecated]           ...           4 years ago
  • 4.0.0-next.0 [deprecated]           ...           4 years ago
  • 3.1.2                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.8.0                                ...           7 years ago
  • 2.7.1                                ...           8 years ago
  • 2.7.0                                ...           8 years ago
  • 2.6.5                                ...           8 years ago
  • 2.6.4                                ...           8 years ago
  • 2.6.3                                ...           8 years ago
  • 2.6.2                                ...           9 years ago
  • 2.6.1                                ...           9 years ago
  • 2.6.0                                ...           9 years ago
  • 2.6.0-2                                ...           9 years ago
  • 2.6.0-1                                ...           9 years ago
  • 2.6.0-0                                ...           9 years ago
  • 2.5.3                                ...           9 years ago
  • 2.5.2                                ...           9 years ago
  • 2.5.1                                ...           9 years ago
  • 2.5.0                                ...           9 years ago
  • 2.5.0-1                                ...           9 years ago
  • 2.4.2                                ...           9 years ago
  • 2.4.1                                ...           9 years ago
  • 2.4.0                                ...           9 years ago
  • 2.3.1                                ...           9 years ago
  • 2.3.0                                ...           9 years ago
  • 2.2.5                                ...           9 years ago
  • 2.2.4                                ...           9 years ago
  • 2.2.3                                ...           9 years ago
  • 2.2.2                                ...           9 years ago
  • 2.2.1                                ...           9 years ago
  • 2.2.0                                ...           9 years ago
  • 2.1.0                                ...           9 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
  • 0.12.1                                ...           10 years ago
  • 0.12.0                                ...           10 years ago
  • 0.11.0                                ...           10 years ago
  • 0.10.3                                ...           11 years ago
  • 0.10.2                                ...           11 years ago
  • 0.10.1                                ...           11 years ago
  • 0.10.0                                ...           11 years ago
  • 0.9.2                                ...           11 years ago
  • 0.9.1                                ...           11 years ago
  • 0.9.0                                ...           11 years ago
  • 0.8.6                                ...           11 years ago
  • 0.8.5                                ...           11 years ago
  • 0.8.4                                ...           11 years ago
  • 0.8.3                                ...           12 years ago
  • 0.8.2                                ...           12 years ago
  • 0.8.1                                ...           12 years ago
  • 0.8.0                                ...           12 years ago
  • 0.7.3                                ...           12 years ago
  • 0.7.2                                ...           13 years ago
  • 0.7.1                                ...           13 years ago
  • 0.7.0                                ...           13 years ago
  • 0.6.7                                ...           13 years ago
  • 0.6.6                                ...           13 years ago
  • 0.6.5                                ...           13 years ago
  • 0.6.4                                ...           13 years ago
  • 0.6.3                                ...           13 years ago
  • 0.6.2                                ...           13 years ago
  • 0.6.1                                ...           13 years ago
  • 0.6.0                                ...           14 years ago
  • 0.5.11                                ...           14 years ago
  • 0.5.10                                ...           14 years ago
  • 0.5.9                                ...           14 years ago
  • 0.5.8                                ...           14 years ago
  • 0.5.7                                ...           14 years ago
  • 0.5.6                                ...           14 years ago
  • 0.5.5                                ...           14 years ago
  • 0.5.4                                ...           14 years ago
  • 0.5.3                                ...           14 years ago
  • 0.5.2                                ...           14 years ago
  • 0.5.1                                ...           14 years ago
  • 0.5.0                                ...           14 years ago
  • 0.4.2                                ...           14 years ago
  • 0.4.1                                ...           14 years ago
  • 0.4.0                                ...           14 years ago
  • 0.3.9                                ...           14 years ago
  • 0.3.7                                ...           14 years ago
  • 0.3.6                                ...           14 years ago
  • 0.3.5                                ...           14 years ago
  • 0.3.4                                ...           14 years ago
  • 0.3.3                                ...           14 years ago
  • 0.3.2                                ...           14 years ago
  • 0.3.1                                ...           14 years ago
  • 0.3.0                                ...           14 years ago
  • 0.2.6                                ...           14 years ago
  • 0.2.4                                ...           14 years ago
  • 0.2.3                                ...           14 years ago
  • 0.2.2                                ...           14 years ago
  • 0.2.1                                ...           14 years ago
  • 0.2.0                                ...           14 years ago
  • 0.1.2                                ...           14 years ago
  • 0.1.1                                ...           14 years ago
  • 0.1.0                                ...           14 years ago
  • 0.0.8                                ...           14 years ago
  • 0.0.7                                ...           14 years ago
  • 0.0.4                                ...           14 years ago
  • 0.0.3                                ...           14 years ago
  • 0.0.2                                ...           14 years ago
  • 0.0.1                                ...           14 years ago
Downloads
Total 83
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (16)

© 2010 - cnpmjs.org x YWFE | Home | YWFE