Skip to content

Instantly share code, notes, and snippets.

@horatio-sans-serif
Created May 4, 2010 02:42
Show Gist options
  • Save horatio-sans-serif/388883 to your computer and use it in GitHub Desktop.
Save horatio-sans-serif/388883 to your computer and use it in GitHub Desktop.
$ NODE_PATH=/Users/brian/projects/redis-node-client/lib:$NODE_PATH node test-mget.js
DEBUG: [ENQUEUE] Not connected. Request queued. There are 1 requests queued.
DEBUG: [FLUSH QUEUE] 1 queued request buffers.
DEBUG: [ENQUEUE] Not connected. Request queued. There are 2 requests queued.
DEBUG: [FLUSH QUEUE] 2 queued request buffers.
DEBUG: [ENQUEUE] Not connected. Request queued. There are 3 requests queued.
DEBUG: [CONNECT]
DEBUG: [FLUSH QUEUE] 3 queued request buffers.
DEBUG: [DEQUEUE/SEND] *3<CRLF>$3<CRLF>set<CRLF>$3<CRLF>foo<CRLF>$3<CRLF>bar<CRLF>. queued buffers remaining = 2
DEBUG: [DEQUEUE/SEND] *3<CRLF>$3<CRLF>set<CRLF>$3<CRLF>baz<CRLF>$3<CRLF>buz<CRLF>. queued buffers remaining = 1
DEBUG: [RECV] +OK<CRLF>+OK<CRLF>
DEBUG: [FLUSH QUEUE] 1 queued request buffers.
DEBUG: [DEQUEUE/SEND] *3<CRLF>$4<CRLF>mget<CRLF>$3<CRLF>foo<CRLF>$3<CRLF>baz<CRLF>. queued buffers remaining = 0
DEBUG: [RECV] *2<CRLF>$3<CRLF>bar<CRLF>$3<CRLF>buz<CRLF>
var sys = require("sys"),
assert = require("assert"),
redis = require("redis-client");
redis.debugMode = true;
function showContext(context) {
sys.error("\n");
sys.log(context + " FAILED!");
sys.error("");
}
function checkEqual(actual, expected, context) {
try {
assert.equal(actual, expected);
} catch (e) {
showContext(context);
throw e;
}
}
function expectOK(context) {
return function (err, truthiness) {
if (err) assert.fail(err, context);
checkEqual(typeof(truthiness), 'boolean', context);
checkEqual(truthiness, true, context);
};
}
function testMGET() {
client.set('foo', 'bar', expectOK("testMGET"));
client.set('baz', 'buz', expectOK("testMGET"));
client.mget('foo', 'baz', function (err, values) {
if (err) assert.fail(err, "testMGET");
checkEqual(values[0], 'bar', "testMGET");
checkEqual(values[1], 'buz', "testMGET");
process.exit(0);
});
}
var client = redis.createClient();
testMGET();
@tritonrc
Copy link

tritonrc commented May 4, 2010

Try changing line 31 to client.mget(['foo', 'baz'], function (err, values) {

@horatio-sans-serif
Copy link
Author

Well, that doesn't work because that's not the API.

I suggest that if you have an array that you push the callback function onto it and then use client.mget.apply(client, the_aforementioned_array).

client.mget.apply(client, ['foo', 'baz', function (err, values) {
    if (err) assert.fail(err, "testMGET");
    checkEqual(values[0], 'bar', "testMGET");
    checkEqual(values[1], 'buz', "testMGET");

    process.exit(0);
}]);

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