Skip to content

Instantly share code, notes, and snippets.

@horatio-sans-serif
Created April 5, 2010 22:30
Show Gist options
  • Save horatio-sans-serif/356972 to your computer and use it in GitHub Desktop.
Save horatio-sans-serif/356972 to your computer and use it in GitHub Desktop.
function testSETANDGETMULTIBYTE() {
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語
var buffer = new Buffer(32);
var size = buffer.utf8Write(testValue);
client.set('testUtf8Key', buffer.slice(0,size), expectOK("testSETANDGETMULTIBYTE"))
client.get('testUtf8Key', function (err, value) {
if (err) assert.fail(err, "testSETANDGETMULTIBYTE");
sys.debug("size="+size+"; value.length="+value.length+"; testValue.length="+testValue.length);
checkEqual(value.utf8Slice(0, value.length), testValue, "testSETANDGETMULTIBYTE");
});
}
DEBUG: reply: {"type":"BULK","value":{"0":195,"1":182,"2":230,"3":151,"4":165,"5":230,"6":156,"7":172,"8":232,"9":170,"10":158,"11":0,"length":12}}
DEBUG: from command: get
DEBUG: size=12; value.length=12; testValue.length=4
~/projects/redis-node-client(nodejs_buffers_and_streams) ⚡ node test.js
DEBUG: [CONNECTED]
DEBUG:
DEBUG: Testing SETANDGETMULTIBYTE
DEBUG: =========================================
DEBUG: [SEND (24 bytes)] *2<CRLF>$6<CRLF>select<CRLF>$2<CRLF>14<CRLF>
DEBUG: [SEND (17 bytes)] *1<CRLF>$7<CRLF>flushdb<CRLF>
DEBUG: [SEND (24 bytes)] *2<CRLF>$6<CRLF>select<CRLF>$2<CRLF>15<CRLF>
DEBUG: [SEND (17 bytes)] *1<CRLF>$7<CRLF>flushdb<CRLF>
DEBUG: [SEND (50 bytes)] *3<CRLF>$3<CRLF>set<CRLF>$11<CRLF>testUtf8Key<CRLF>$12<CRLF>ö日本語<CRLF>
DEBUG: [SEND (31 bytes)] *2<CRLF>$3<CRLF>get<CRLF>$11<CRLF>testUtf8Key<CRLF>
DEBUG: [RECV] +OK<CRLF>
DEBUG: reply: {"type":"INLINE","value":true}
DEBUG: from command: select
DEBUG: [RECV] +OK<CRLF>+OK<CRLF>+OK<CRLF>+OK<CRLF>$12<CRLF>ö日本語<CRLF>
DEBUG: reply: {"type":"INLINE","value":true}
DEBUG: from command: flushdb
DEBUG: reply: {"type":"INLINE","value":true}
DEBUG: from command: select
DEBUG: reply: {"type":"INLINE","value":true}
DEBUG: from command: flushdb
DEBUG: reply: {"type":"INLINE","value":true}
DEBUG: from command: set
DEBUG: reply: {"type":"BULK","value":{"0":195,"1":182,"2":230,"3":151,"4":165,"5":230,"6":156,"7":172,"8":232,"9":170,"10":158,"11":0,"length":12}}
DEBUG: from command: get
DEBUG: size=12; value.length=12; testValue.length=4
DEBUG:
DEBUG: VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
DEBUG: testSETANDGETMULTIBYTE FAILED!
DEBUG: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEBUG:
AssertionError: "\u00f6\u65e5\u672c\u8a9e" == "\u00f6\u65e5\u672c\u8a9e\u0000"
at checkEqual (/Users/brian/projects/redis-node-client/test.js:61:16)
at /Users/brian/projects/redis-node-client/test.js:356:26
at Client.onReply_ (/Users/brian/projects/redis-node-client/redisclient.js:378:25)
at /Users/brian/projects/redis-node-client/redisclient.js:152:30
at ReplyParser.feed (/Users/brian/projects/redis-node-client/redisclient.js:207:25)
at Stream.<anonymous> (/Users/brian/projects/redis-node-client/redisclient.js:280:28)
at IOWatcher.callback (net:306:16)
at node.js:813:9
@horatio-sans-serif
Copy link
Author

Where is \u0000 coming from? Terminating NULL of a C string in Node? Hmm....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment