ioredisNode.js 的 Redis 客戶端
ioredis 是一個(gè)用于 Node.js/io.js 的 Redis 客戶端,強(qiáng)健、功能強(qiáng)大且全面。
要求 Redis >= 2.6.12 ,Node.js >= 0.10.16)
具有以下特性
-
功能完備。支持 Cluster, Sentinel, Pipelining,以及 Lua scripting & Pub/Sub(同時(shí)支持二進(jìn)制消息)
-
高性能
-
友好的 API,支持使用 Node callbacks 以及 Bluebird promises
-
抽象 Lua 腳本,可定義自定義命令
-
支持二進(jìn)制數(shù)據(jù)
-
支持 TLS
-
支持離線隊(duì)列和準(zhǔn)備檢查
-
支持 ES6 類型,例如 Map and Set
-
支持 GEO 命令(Redis 3.2 Unstable)
-
完善的錯(cuò)誤處理策略
示例代碼 - 基本用法
var Redis = require('ioredis');
var redis = new Redis();
redis.set('foo', 'bar');
redis.get('foo', function (err, result) {
console.log(result);
});
// Or using a promise if the last argument isn't a function
redis.get('foo').then(function (result) {
console.log(result);
});
// Arguments to commands are flattened, so the following are the same:
redis.sadd('set', 1, 3, 5, 7);
redis.sadd('set', [1, 3, 5, 7]);
// All arguments are passed directly to the redis server:
redis.set('key', 100, 'EX', 10);評論
圖片
表情
