Comparing version 0.0.1 to 0.0.2
@@ -68,5 +68,6 @@ var _ = require('lodash'); | ||
var result; | ||
var commandStr = '*' + (this.args.length + 1) + '\r\n$' + this.name.length + '\r\n' + this.name + '\r\n'; | ||
if (bufferMode) { | ||
var resultBuffer = new fbuffer.FlexBuffer(); | ||
resultBuffer.write('*' + (this.args.length + 1) + '\r\n$' + this.name.length + '\r\n' + this.name + '\r\n'); | ||
resultBuffer.write(commandStr); | ||
for (i = 0; i < this.args.length; ++i) { | ||
@@ -88,3 +89,6 @@ var arg = this.args[i]; | ||
} else { | ||
result = Command.multiBulk([this.name].concat(this.args)); | ||
result = commandStr; | ||
for (i = 0; i < this.args.length; ++i) { | ||
result += '$' + Buffer.byteLength(this.args[i]) + '\r\n' + this.args[i] + '\r\n'; | ||
} | ||
} | ||
@@ -125,3 +129,3 @@ return result; | ||
// Commands that can be processed when Redis is loading data from disk | ||
VALID_WHEN_LOADING: ['info', 'subscribe', 'unsubscribe', 'psubscribe', 'pubsubscribe', 'publish'], | ||
VALID_WHEN_LOADING: ['info', 'auth', 'select', 'subscribe', 'unsubscribe', 'psubscribe', 'pubsubscribe', 'publish', 'shutdown', 'replconf', 'role', 'pubsub', 'command', 'latency'], | ||
// Commands that can be processed when client is in the subscriber mode | ||
@@ -140,14 +144,2 @@ VALID_IN_SUBSCRIBER_MODE: ['subscribe', 'psubscribe', 'unsubscribe', 'punsubscribe', 'ping', 'quit'], | ||
Command.multiBulk = function (values) { | ||
var str = '*' + values.length + '\r\n'; | ||
for (var i = 0; i < values.length; ++i) { | ||
str += this.bulk(values[i]); | ||
} | ||
return str; | ||
}; | ||
Command.bulk = function (value) { | ||
return '$' + Buffer.byteLength(value) + '\r\n' + value + '\r\n'; | ||
}; | ||
module.exports = Command; |
@@ -82,5 +82,6 @@ var events = require("events"); | ||
if (this.options.return_buffers) { | ||
return this._buffer.slice(start, end); | ||
} | ||
// TODO number? | ||
// if (this.options.return_buffers) { | ||
// return this._buffer.slice(start, end); | ||
// } | ||
@@ -87,0 +88,0 @@ // return the coerced numeric value |
@@ -136,3 +136,3 @@ var _ = require('lodash'); | ||
Redis.prototype.disconnect = function () { | ||
this.status = 'closing'; | ||
this.manuallyClosing = true; | ||
this.connection.end(); | ||
@@ -139,0 +139,0 @@ }; |
@@ -11,3 +11,3 @@ /** | ||
host: 'localhost', | ||
family: 'IPv4', | ||
family: 4, | ||
enableOfflineQueue: true, | ||
@@ -14,0 +14,0 @@ enableReadyCheck: true, |
@@ -127,3 +127,3 @@ var _ = require('lodash'); | ||
if (_.includes(Command.FLAGS.WILL_DISCONNECT, command.name)) { | ||
this.status = 'closing'; | ||
this.manuallyClosing = true; | ||
} | ||
@@ -130,0 +130,0 @@ |
@@ -23,2 +23,23 @@ var Queue = require('fastqueue'); | ||
// AUTH command should be processed before any other commands | ||
if (self.condition.auth) { | ||
console.log(self.condition.auth); | ||
self.sendCommand(new Command('auth', [self.condition.auth], 'utf8', function (err, res) { | ||
console.log('auth', err, res); | ||
if (res === 'OK') { | ||
return; | ||
} | ||
if (err.message.match('no password is set')) { | ||
debug('`auth` is specified in the client but not in the server.'); | ||
} else if (err) { | ||
self.silentEmit('error', new Error('Auth error: ' + err.message)); | ||
} else { | ||
self.silentEmit('error', new Error('Auth failed: ' + res)); | ||
} | ||
})); | ||
} | ||
if (self.condition.select) { | ||
self.sendCommand(new Command('select', [self.condition.select])); | ||
} | ||
if (!self.options.enableReadyCheck) { | ||
@@ -49,4 +70,2 @@ readyHandler(self)(); | ||
var isManuallyClose = self.status === 'closing'; | ||
self.status = 'closed'; | ||
@@ -57,3 +76,4 @@ self.emit('close'); | ||
if (isManuallyClose) { | ||
if (self.manuallyClosing) { | ||
self.manuallyClosing = false; | ||
debug('skip reconnecting since the connection is manually closed.'); | ||
@@ -113,17 +133,2 @@ return; | ||
// AUTH command should be processed before any other commands | ||
if (self.condition.auth) { | ||
self.sendCommand(new Command('auth', [self.condition.auth], 'utf8', function (err, res) { | ||
if (res === 'OK') { | ||
return; | ||
} | ||
if (err.message.match('no password is set')) { | ||
debug('`auth` is specified in the client but not in the server.'); | ||
} else if (err) { | ||
self.silentEmit('error', new Error('Auth error: ' + err.message)); | ||
} else { | ||
self.silentEmit('error', new Error('Auth failed: ' + res)); | ||
} | ||
})); | ||
} | ||
if (self.condition.mode.monitoring) { | ||
@@ -138,5 +143,2 @@ self.sendCommand(new Command('monitor', null, 'utf8', function () { | ||
} else { | ||
if (self.condition.select) { | ||
self.sendCommand(new Command('select', [self.condition.select])); | ||
} | ||
if (self.condition.mode.subscriber) { | ||
@@ -159,2 +161,3 @@ var callback_count = 0; | ||
} | ||
debug('send commands in offline queue: %d', self.offlineQueue.length); | ||
while (self.offlineQueue.length > 0) { | ||
@@ -161,0 +164,0 @@ var command = self.offlineQueue.shift(); |
{ | ||
"name": "ioredis", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A delightful, performance-focused Redis client for Node and io.js", | ||
@@ -10,2 +10,6 @@ "main": "index.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/luin/ioredis.git" | ||
}, | ||
"keywords": [ | ||
@@ -31,4 +35,9 @@ "redis", | ||
"minami": "^1.1.0", | ||
"mocha": "^2.2.1" | ||
"mocha": "^2.2.1", | ||
"sinon": "^1.14.1" | ||
}, | ||
"engines": { | ||
"node": ">= 0.11.16", | ||
"iojs": ">= 1.0.0" | ||
} | ||
} |
ioredis | ||
======== | ||
[![Join the chat at https://gitter.im/luin/ioredis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luin/ioredis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![Build Status](https://travis-ci.org/luin/ioredis.png?branch=master)](https://travis-ci.org/luin/ioredis) | ||
[![Dependency Status](https://david-dm.org/luin/ioredis.svg)](https://david-dm.org/luin/ioredis) | ||
[![Join the chat at https://gitter.im/luin/ioredis](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/luin/ioredis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[WIP] A delightful, performance-focused Redis client for Node and io.js | ||
**[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](http://www.alibaba.com/). | ||
0. Full-featured. It supports [Cluster](http://redis.io/topics/cluster-tutorial), [Sentinel](redis.io/topics/sentinel), [Pipelining](http://redis.io/topics/pipelining) and of course [Lua scripting](http://redis.io/commands/eval) & [Pub/Sub](http://redis.io/topics/pubsub) | ||
0. High performance. | ||
0. Delightful API supports both Node-style callback and Promise. | ||
0. Supports Redis commands transforming. | ||
0. Abstraction for Transaction, Lua scripting and `SCAN`, `SSCAN`, `ZSCAN`, `HSCAN`. | ||
0. Supports binary data. | ||
0. Support for both TCP/IP and UNIX domain sockets. | ||
0. Flexible system for defining custom command and registering command plugins. | ||
0. Supports offine queue and ready checking. | ||
0. Supports ES6 types such as `Map` and `Set`. | ||
Instal | ||
@@ -17,3 +35,3 @@ ------ | ||
Usage | ||
Basic Usage | ||
------ | ||
@@ -30,6 +48,46 @@ | ||
// or using promise | ||
// 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: | ||
```javascript | ||
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: | ||
```javascript | ||
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: | ||
```javascript | ||
redis.getBuffer('foo', function (err, result) { | ||
// result is a buffer. | ||
}); | ||
``` |
GLOBAL.expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
GLOBAL.stub = sinon.stub.bind(sinon); | ||
var Redis = GLOBAL.Redis = require('..'); | ||
@@ -4,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
646083
42
2218
92
0
6
2