Skip to content
Browse files

enabled storing and parsing of utf8 values (thx to Alexei)

  • Loading branch information...
1 parent 29965bc commit 2c6f0ea71352f6b6b9153589e05ec311faf86587 @elbart committed Mar 12, 2011
Showing with 17 additions and 1 deletion.
  1. +8 −1 lib/memcache.js
  2. +9 −0 test/test-memcache.js
View
9 lib/memcache.js
@@ -135,7 +135,8 @@ Client.prototype.store = function(cmd, key, value, callback, lifetime, flags)
var set_flags = flags || 0;
var exp_time = lifetime || 0;
- var value_len = value.length || 0;
+ var tml_buf = new Buffer(value);
+ var value_len = tml_buf.length || 0;
var query = [cmd, key, set_flags, exp_time, value_len];
return this.query(query.join(' ') + crlf + value, 'simple', callback);
@@ -269,6 +270,12 @@ Client.prototype.handle_get = function(buffer) {
if (buffer.indexOf('END') == 0) {
return [result_value, end_indicator_len + crlf_len];
+ } else if (buffer.indexOf('VALUE') == 0) {
+ first_line_len = buffer.indexOf(crlf) + crlf_len;
+ var end_indicator_start = buffer.indexOf('END');
+ result_len = end_indicator_start - first_line_len - crlf_len;
+ result_value = buffer.substr(first_line_len, result_len);
+ return [result_value, first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len]
} else {
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var result_len = buffer.substr(0, first_line_len).split(' ')[3];
View
9 test/test-memcache.js
@@ -91,6 +91,15 @@ mc.addHandler(function() {
});
};
+ // test utf8 handling
+ exports['utf8'] = function(beforeExit) {
+ mc.set('key1', 'привет', function() {
+ mc.get('key1', function(r) {
+ assert.equal('привет', r);
+ });
+ });
+ };
+
// test connecting and disconnecting
exports['con disco'] = function(beforeExit) {

0 comments on commit 2c6f0ea

Please sign in to comment.
Something went wrong with that request. Please try again.