JSPM

  • Created
  • Published
  • Downloads 7629707
  • Score
    100M100P100Q206151F
  • License MIT

A delightful, performance-focused Redis client for Node and io.js

Package Exports

  • ioredis
  • ioredis/lib/command
  • ioredis/lib/utils
  • ioredis/package.json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ioredis) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ioredis

Build Status Dependency Status Join the chat at https://gitter.im/luin/ioredis

[WIP] A delightful, performance-focused Redis client for Node and io.js

Support Redis >= 2.6.12 and (Node.js >= 0.11.6 or io.js).

Feature

ioredis is a robust, full-featured Redis client used in the biggest online commerce company Alibaba.

  1. Full-featured. It supports Cluster, Sentinel, Pipelining and of course Lua scripting & Pub/Sub
  2. High performance.
  3. Delightful API supports both Node-style callback and Promise.
  4. Supports Redis commands transforming.
  5. Abstraction for Transaction, Lua scripting and SCAN, SSCAN, ZSCAN, HSCAN.
  6. Supports binary data.
  7. Support for both TCP/IP and UNIX domain sockets.
  8. Flexible system for defining custom command and registering command plugins.
  9. Supports offine queue and ready checking.
  10. Supports ES6 types such as Map and Set.

Instal

$ npm install ioredis

Basic Usage

var Redis = require('ioredis');
var redis = new Redis();

redis.set('foo', 'bar');
redis.get('foo', function (err, result) {
  console.log(result);
});

// or using promise if the last argument isn't a function
redis.get('foo').then(function (result) {
  console.log(result);
});

// Arguments will be flatten, so both the following two line are same:
redis.sadd('set', 1, 3, 5, 7);
redis.sadd('set', [1, 3, 5, 7]);

Connect to Redis

When a new Redis instance is created, a connection to Redis will be created at the same time.

You can specify which Redis to connect by:

new Redis()       // Will connect to 127.0.0.1:6379
new Redis(6380)   // 127.0.0.1:6380
new Redis(6379, '192.168.1.1')        // 192.168.1.1:6379
new Redis('redis://127.0.0.1:6380')   // 127.0.0.1:6380
new Redis('/tmp/redis.sock')
new Redis({
  port: 6379          // Redis port
  host: '127.0.0.1'   // Redis host
  family: 4           // 4(IPv4) or 6(IPv6)
})

Handle Binary Data

Arguments can be buffers:

redis.set('foo', new Buffer('bar'));

And every command has a buffer method(by adding a suffix of "Buffer" to the command name) to reply a buffer instead of a utf8 string:

redis.getBuffer('foo', function (err, result) {
  // result is a buffer.
});