Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are multiple ways to debug a Redis client with node.js.</p> <p>First you can rely on the Redis monitor feature to log every commands received by the Redis server:</p> <pre><code>&gt; src/redis-cli monitor OK 1371134499.182304 [0 172.16.222.72:51510] "info" 1371134499.185190 [0 172.16.222.72:51510] "zinterstore" "tmp" "2" "red,round" </code></pre> <p>You can see the zinterstore command received by Redis is ill-formed.</p> <p>Then, you can activate the debugging mode of node_redis by adding the following line in your script:</p> <pre><code>redis.debug_mode = true; </code></pre> <p>It will output the Redis protocol at runtime:</p> <pre><code>Sending offline command: zinterstore send ncegcolnx243:6379 id 1: *4 $11 zinterstore $3 tmp $1 2 $9 red,round send_command buffered_writes: 0 should_buffer: false net read ncegcolnx243:6379 id 1: -ERR syntax error </code></pre> <p>Then, you can use <a href="http://nodejs.org/api/debugger.html">node.js debugger</a>. Put a debugger breakpoint in the code in the following way:</p> <pre><code>function search(tags, page, callback) { debugger; // breakpoint is here client.ZINTERSTORE("tmp", tags.length, tags, function(err, replies){ console.log(err); console.log(replies); callback('ok') }); } </code></pre> <p>You can then launch the script with node in debug mode:</p> <pre><code>$ node debug test.js &lt; debugger listening on port 5858 connecting... ok break in D:\Data\NodeTest\test.js:1 1 var redis = require("redis"); 2 var client = redis.createClient( 6379, "ncegcolnx243" ); 3 debug&gt; help Commands: run (r), cont (c), next (n), step (s), out (o), backtrace (bt), setBreakpoint (sb), clearBreakpoint (cb), watch, unwatch, watchers, repl, restart, kill, list, scripts, breakOnException, breakpoints, version debug&gt; cont break in D:\Data\NodeTest\test.js:8 6 function search(tags, page, callback) { 7 8 debugger; 9 client.ZINTERSTORE("tmp", tags.length, tags, function(err, replies){ 10 console.log(err); ... use n(ext) and s(tep) commands ... </code></pre> <p>By stepping through the code, you will realize that the command array is not correct because the tags are serialized and processed as a unique parameter.</p> <p>Changing the code as follows will fix the problem:</p> <pre><code>var cmd = [ "tmp", tags.length ]; client.zinterstore( cmd.concat(tags), function(err, replies) { ... }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload