Permalink
Browse files

Merge pull request #57 from privman/master

Preserve type for numeric values
  • Loading branch information...
2 parents 0e807b9 + ce72701 commit d1c0afd8125c7770a92272e9aedf6ee5e8fe5c5a @3rd-Eden committed Oct 3, 2012
Showing with 11 additions and 6 deletions.
  1. +9 −4 lib/memcached.js
  2. +2 −2 tests/memcached-get-set.test.js
View
@@ -97,7 +97,8 @@ Client.config = {
, BUFFER = 1E2
, CONTINUE = 1E1
, FLAG_JSON = 1<<1
- , FLAG_BINARY = 2<<1;
+ , FLAG_BINARY = 1<<2
+ , FLAG_NUMERIC = 1<<3;
var memcached = nMemcached.prototype = new EventEmitter
, privates = {}
@@ -411,6 +412,9 @@ Client.config = {
case FLAG_JSON:
dataSet = JSON.parse(dataSet);
break;
+ case FLAG_NUMERIC:
+ dataSet = +dataSet;
+ break;
case FLAG_BINARY:
tmp = new Buffer(dataSet.length);
tmp.write(dataSet, 0, 'binary');
@@ -739,11 +743,12 @@ Client.config = {
if (Buffer.isBuffer(value)) {
flag = FLAG_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;
value = JSON.stringify(value);
- } else {
- value = value.toString();
}
length = Buffer.byteLength(value);
@@ -150,8 +150,8 @@ describe("Memcached GET SET", function() {
assert.ok(!error);
- assert.ok(typeof answer === 'string');
- answer.should.eql(answer);
+ assert.ok(typeof answer === 'number');
+ answer.should.eql(message);
memcached.end(); // close connections
assert.equal(callbacks, 2);

0 comments on commit d1c0afd

Please sign in to comment.