• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

thunk-redis: A redis client with pipelining, rely on thunks, support promise.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

thunk-redis

开源软件地址:

https://gitee.com/zensh/thunk-redis

开源软件介绍:

thunk-redis

A redis client with pipelining, rely on thunks, support promise.

NPM versionBuild StatusTalk topic

thunks

Demo(examples)

default thunk API:

var redis = require('thunk-redis');var client = redis.createClient({  database: 0});client.on('connect', function() {  console.log('redis connected!');});client.info('server')(function(error, res) {  console.log('redis server info:', res);  return this.dbsize();})(function(error, res) {  console.log('surrent database size:', res);  return this.select(0);})(function(error, res) {  console.log('select database 0:', res);  return this.quit();})(function(error, res) {  console.log('redis client quit:', res);});

use promise API:

var redis = require('thunk-redis');var client = redis.createClient({  database: 1,  usePromise: true});client.on('connect', function() {  console.log('redis connected!');});client  .info('server')  .then(function(res) {    console.log('redis server info:', res);    return client.dbsize();  })  .then(function(res) {    console.log('surrent database size:', res);    return client.select(0);  })  .then(function(res) {    console.log('select database 0:', res);    return client.quit();  })  .then(function(res) {    console.log('redis client quit:', res);  });

support generator in thunk API:

var redis = require('thunk-redis');var client = redis.createClient();client.select(1)(function*(error, res) {  console.log(error, res);  yield this.set('foo', 'bar');  yield this.set('bar', 'baz');  console.log('foo -> %s', yield this.get('foo'));  console.log('bar -> %s', yield this.get('bar'));  var user = {    id: 'u001',    name: 'jay',    age: 24  };  // transaction, it is different from node_redis!  yield [    this.multi(),    this.set(user.id, JSON.stringify(user)),    this.zadd('userAge', user.age, user.id),    this.pfadd('ageLog', user.age),    this.exec()  ];  return this.quit();})(function(error, res) {  console.log(error, res);});

Benchmark

  thunk-redis git:(master)  node --harmony benchmark/index.jsredis(N):node_redisOKredis(T):thunk-redisOKStart...redis(N): PING 49358 ops/sec 100%redis(T): PING 54495 ops/sec 110.4%redis(N): SET small string 39062 ops/sec 100%redis(T): SET small string 44523 ops/sec 114.0%redis(N): GET small string 43859 ops/sec 100%redis(T): GET small string 47687 ops/sec 108.7%redis(N): SET long string 28320 ops/sec 100%redis(T): SET long string 35323 ops/sec 124.7%redis(N): GET long string 30432 ops/sec 100%redis(T): GET long string 26645 ops/sec 87.6%redis(N): INCR 46061 ops/sec 100%redis(T): INCR 48756 ops/sec 105.9%redis(N): LPUSH 39824 ops/sec 100%redis(T): LPUSH 45289 ops/sec 113.7%redis(N): LRANGE 100 8322 ops/sec 100%redis(T): LRANGE 100 10094 ops/sec 121.3%

Installation

Node.js:

npm install thunk-redis

API(More)

  1. redis.createClient([port], [host], [options])
  2. redis.createClient([path], [options])
  3. redis.log([...])

redis.log

Helper tool, print result or error stack.

var client = redis.createClient();client.info()(redis.log);

redis.createClient

var client1 = redis.createClient();var client2 = redis.createClient({database: 2});var client3 = redis.createClient(6379, {database: 2});var client4 = redis.createClient(6379, '127.0.0.1', {database: 2});var client5 = redis.createClient('/tmp/redis.sock');var client6 = redis.createClient('/tmp/redis.sock', {database: 2});
  • options.authPass: Optional, Type: String, Default: ''.

  • options.database: Optional, Type: Number, Default: 0.

  • options.debugMode: Optional, Type: Boolean, Default: false.

    Print request data and response data.

  • options.returnBuffers: Optional, Type: Boolean, Default: false.

  • options.usePromise: Optional, Type: Boolean or Promise constructor, Default: false.

    Export promise commands API.

    Use default Promise:

    var redis = require('thunk-redis');var client = redis.createClient({  database: 1,  usePromise: true});

    Use bluebird:

    var redis = require('thunk-redis');var Bluebird = require('bluebird');var client = redis.createClient({  database: 1,  usePromise: Bluebird});
  • options.noDelay: Optional, Type: Boolean, Default: true.

    Disables the Nagle algorithm. By default TCP connections use the Nagle algorithm, they buffer data before sending it off. Setting true for noDelay will immediately fire off data each time socket.write() is called.

  • options.keepAlive: Optional, Type: Boolean, Default: true.

    Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.

  • options.timeout: Optional, Type: Number, Default: 0.

    Sets the socket to timeout after timeout milliseconds of inactivity on the socket. If timeout is 0, then the existing idle timeout is disabled.

    When an idle timeout is triggered the socket will receive a 'timeout' event but the connection will not be severed.

  • options.retryDelay: Optional, Type: Number, Default: 5000.

  • options.maxAttempts: Optional, Type: Number, Default: 5.

  • options.commandsHighWater: Optional, Type: Number, Default: 10000.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap