title: How to wait the "set" function of ioredis library in nodejs script? ( I think answerers need not know ioredis.)
body: <p>Let me put my node.js script bellow.</p>
  <p>It failed because probably the redis.disconnect() call finished before redis.set() calls completed.</p>
  <p>How can I make redis.disconnet() wait until all &quot;set()&quot; calls has completed?</p>
  <p>I need to call redis.disconnect() because I want the script to close on the completion in the terminal. (e.g. node myscript.js -x1)</p>
  <p><a href="https://github.com/luin/ioredis" rel="nofollow noreferrer">https://github.com/luin/ioredis</a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var Redis = require("ioredis");
  var redis = new Redis();
  for (var i = 0; i &lt; process.argv.length; ++i) {
      var ai = process.argv[i];
     
      if (ai == "-x1") {
          redis.set("x", "1");
          
      }
      if (ai == "-x2") {
          redis.set("x", "2");
          
      }
  }
  redis.disconnect()</code></pre>
  </div>
  </div>
  </p>