Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[fix] Added STAT parsing
  • Loading branch information
3rd-Eden committed Jan 21, 2013
1 parent 00e0aa4 commit f15e6e4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
13 changes: 12 additions & 1 deletion index.js
Expand Up @@ -127,6 +127,7 @@ Parser.prototype.parse = function parse() {
}

// @TODO Order this in order of importance
// @TODO see if we can reduce the amount i += calls by setting rn value..
if (charCode === 67) {
// CLIENT_ERROR (charCode 67 === C):
//
Expand Down Expand Up @@ -255,7 +256,17 @@ Parser.prototype.parse = function parse() {
// STAT:
//
// Received a stat from the server.
// @TODO
var pos = data.indexOf(' ', i + 5)
, val;

msg = data.slice(i + 5, pos);
val = data.slice(i + 6 + msg.length, rn);

this.emit('response', 'STAT', msg, val);

length = msg.length + val.length + 7;
i += length;
bytesRemaining -= length;
}
} else if (charCode === 84) {
// TOUCHED (charCode 84 === T):
Expand Down
36 changes: 34 additions & 2 deletions test/protocol.test.js
Expand Up @@ -331,8 +331,40 @@ describe('memcached-stream', function () {
});

describe('STAT', function () {
it('emits an `response` event when encountered');
it('correctly cleans the queue');
var data = 'STAT listen_disabled_num 1000\r\n';

it('emits an `response` event when encountered', function (done) {
var memcached = new Parser();

memcached.on('response', function (command, key, value) {
expect(command).to.equal('STAT');
expect(key).to.equal('listen_disabled_num');
expect(value).to.equal('1000');

// should clear the cache
process.nextTick(function () {
expect(memcached.queue).to.equal('');

done();
});
});

memcached.write(data);
});

it('correctly cleans the queue', function (done) {
var memcached = new Parser();

memcached.on('response', function (err) {
process.nextTick(function () {
expect(memcached.queue).to.equal('BANANANANA');

done();
});
});

memcached.write(data+ 'BANANANANA');
});
});

describe('STORED', function () {
Expand Down

0 comments on commit f15e6e4

Please sign in to comment.