Skip to content

Commit

Permalink
Merge pull request #57 from privman/master
Browse files Browse the repository at this point in the history
Preserve type for numeric values
  • Loading branch information
3rd-Eden committed Oct 3, 2012
2 parents 0e807b9 + ce72701 commit d1c0afd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/memcached.js
Expand Up @@ -97,7 +97,8 @@ Client.config = {
, BUFFER = 1E2 , BUFFER = 1E2
, CONTINUE = 1E1 , CONTINUE = 1E1
, FLAG_JSON = 1<<1 , FLAG_JSON = 1<<1
, FLAG_BINARY = 2<<1; , FLAG_BINARY = 1<<2
, FLAG_NUMERIC = 1<<3;


var memcached = nMemcached.prototype = new EventEmitter var memcached = nMemcached.prototype = new EventEmitter
, privates = {} , privates = {}
Expand Down Expand Up @@ -411,6 +412,9 @@ Client.config = {
case FLAG_JSON: case FLAG_JSON:
dataSet = JSON.parse(dataSet); dataSet = JSON.parse(dataSet);
break; break;
case FLAG_NUMERIC:
dataSet = +dataSet;
break;
case FLAG_BINARY: case FLAG_BINARY:
tmp = new Buffer(dataSet.length); tmp = new Buffer(dataSet.length);
tmp.write(dataSet, 0, 'binary'); tmp.write(dataSet, 0, 'binary');
Expand Down Expand Up @@ -739,11 +743,12 @@ Client.config = {
if (Buffer.isBuffer(value)) { if (Buffer.isBuffer(value)) {
flag = FLAG_BINARY; flag = FLAG_BINARY;
value = value.toString('binary'); value = value.toString('binary');
} else if (valuetype !== 'string' && valuetype !== 'number') { } else if (valuetype === 'number') {
flag = FLAG_NUMERIC;
value = value.toString();
} else if (valuetype !== 'string') {
flag = FLAG_JSON; flag = FLAG_JSON;
value = JSON.stringify(value); value = JSON.stringify(value);
} else {
value = value.toString();
} }


length = Buffer.byteLength(value); length = Buffer.byteLength(value);
Expand Down
4 changes: 2 additions & 2 deletions tests/memcached-get-set.test.js
Expand Up @@ -150,8 +150,8 @@ describe("Memcached GET SET", function() {


assert.ok(!error); assert.ok(!error);


assert.ok(typeof answer === 'string'); assert.ok(typeof answer === 'number');
answer.should.eql(answer); answer.should.eql(message);


memcached.end(); // close connections memcached.end(); // close connections
assert.equal(callbacks, 2); assert.equal(callbacks, 2);
Expand Down

0 comments on commit d1c0afd

Please sign in to comment.