node.js express - attempting the redis MULTI / EXEC command
<p>I have a noob question. 
I'm writing my first node.js / express REST API. For one of my POST methods, the clients can send multiple "records" to save in the DB in one shot. </p>

<p>i'm trying to write my MULTI / EXEC logic... use the samples in the readme file that comes with the redis client. </p>

<p>But I can't see what I'm doing wrong. </p>

<p>Here's how I write to my hash manually via redis-cli</p>

<pre><code>127.0.0.1:6379&gt; hset widget:widget1 00:00:00_00:00:00 123@testmeout.com
(integer) 1
127.0.0.1:6379&gt; 
</code></pre>

<p>This is what my code looks like </p>

<p><strong>common.js</strong></p>

<pre><code>var redis = require('redis');
exports.redis = redis.createClient('6379','10.2.2.2');
</code></pre>

<p><strong>widgets.js</strong></p>

<pre><code>var common = require('./common');
var redis = common.redis;

router.post('/', function(req, res, next) {

    // do a bunch of stuff. 
    // multi test.  all hardcoded for now until i understand how it works.
    redis.multi([
        ["hset", "widget:widget1", "00:00:00_00:00:00", "123@testmeout.com",redis.print ],
        ["hset", "widget:widget2", "00:00:00_00:00:00", "222@willywonka.com", redis.print]
    ]).exec(function (err, replies) {
            if (err ){
                    console.log(err);
            } else {
                console.log(replies);
            }
    });
</code></pre>

<p>On the console, I see </p>

<pre><code> [ undefined, undefined ]
</code></pre>

<p>for the "replies" output.  I don't get any errors.  But I also can't see any of my hashes in the database.  I tried this query on the redis-cli to verify that nothing was added to the database: </p>

<pre><code>127.0.0.1:6379&gt; scan 0 match widget:w* count 10000000
1) "0"
2) (empty list or set)
</code></pre>

<p><strong>EDIT 1</strong></p>

<p>As a test I tried to add a HGETALL call in my multi.  and it works.  Notice the multi code now: </p>

<pre><code>redis.multi([
    ["hgetall", "widget:7449890"],
    ["hset", "widget:widget1", "00:00:00_00:00:00", "123@testmeout.com",redis.print ],
    ["hset", "widget:widget2", "00:00:00_00:00:00", "222@willywonka.com", redis.print]
]).exec(function (err, replies) {
        if (err ){
                console.log(err);
        } else {
            console.log(replies);
        }
});
</code></pre>

<p>Which returns the following on the console: </p>

<pre><code>[ { '00:00:00_00:00:00': 'johndoe@test.net' },
  undefined,
  undefined ]
</code></pre>

<p>Also the other interesting artifact I found is this - I turned on redis-cli monitoring as my node js app runs and I see the following queries being made against the database: </p>

<pre><code>1476985090.048093 [0 10.238.36.117:36069] "multi"
1476985090.048118 [0 10.238.36.117:36069] "hgetall" "widget:7449890"
1476985090.048137 [0 10.238.36.117:36069] "exec"
1476985092.800405 [0 10.238.36.118:6379] "PING"
</code></pre>

<p>I guess thereby proving that the HSET commands are not being executed at all. </p>

<p>I also tried changing hset to hsetall ... but it's the same results.  No errors but also no set command being executed. </p>