title: Managing amazon translation with redis
body: <p>I have to manage a traduction of a json with aws from amazon and saving the cache in redis.</p>
  <pre class="lang-js prettyprint-override"><code>async function translateSomething(trans, p1, sourceLan, targetLan) {
    var paramsName = {
      Text: p1,
      SourceLanguageCode: sourceLan,
      TargetLanguageCode: targetLan,
    };
  
    let myPromise = () =&gt;
      new Promise((resolve, reject) =&gt; {
        trans.translateText(paramsName, function (err, data) {
          if (err) throw err;
          if (data) {
            console.log(&quot;translated&quot;, data.TranslatedText);
            resolve(data.TranslatedText);
          }
        });
      });
  
    let res = await myPromise();
    return res;
  }
  // and this function to check if the value is in the menu or not
  
  function storeOrFound(p1, value, sourceLan, targetLan) {
    return redisClient.get(p1, async (err, result) =&gt; {
      if (err) console.log(&quot;err&quot;, err);
      if (result) {
        console.log(&quot;element is already in cache&quot;, JSON.parse(result).val);
  
        let tmp = JSON.parse(result).val;
  
        return tmp;
      } else {
        var translate = new AWS.Translate({ region: AWS.config.region });
  
        let val = await translateSomething(
          translate,
          value,
          sourceLan,
          targetLan,
        );
  
        redisClient.setex(
          p1,
          3600,
          JSON.stringify({ source: &quot;Redis Cache&quot;, val }),
        );
  
        return val;
      }
    });
  }
  // and after i execute the query of the db i use this function to check if is present or not on the db or not
  
  something().then((doc) =&gt; {
    for (let i = 0; i &lt; doc.items.length; i++) {
      const menuRedisKeyName = `name:${doc.items[i].name}21`;
      doc.items[i].name = storeOrFound(
        menuRedisKeyName,
        doc.items[i].name,
        menuLang,
        targetLan,
      );
    }
    console.log(&quot;JSON&quot;, JSON.stringify(doc));
    res.end(JSON.stringify(doc));
  });
  </code></pre>
  <p>The problem is that the method storeOrFound returns true or false (because return redisClient.get return true or false whether the object is present or not . Any ideas for managing this problem? Also on the console i see that the console.log(&quot; element is already in cache&quot;..) is printed at the end. Did i miss something on synchronization?</p>