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
[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.
- Full-featured. It supports Cluster, Sentinel, Pipelining and of course Lua scripting & Pub/Sub
- High performance.
- Delightful API supports both Node-style callback and Promise.
- Supports Redis commands transforming.
- Abstraction for Transaction, Lua scripting and
SCAN
,SSCAN
,ZSCAN
,HSCAN
. - Supports binary data.
- Support for both TCP/IP and UNIX domain sockets.
- Flexible system for defining custom command and registering command plugins.
- Supports offine queue and ready checking.
- Supports ES6 types such as
Map
andSet
.
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.
});