storage/redis_old.js
function syncRedis() {
    // if memStore has changed...
    if(JSON.stringify(memCache) !== JSON.stringify(memStore)) {
      return when.promise((resolve, reject) => {
        var serializedStore = JSON.stringify(memStore);
        redis.set(name, serializedStore, err => {
          if(err) {
            reject(err);
          } else {
            resolve(true);
          }
        });
      })
      .delay(syncInterval)
      .catch(err => {
        console.log(err.stack);
        return when(true);
      })
      .finally(() => {
        memCache = _.cloneDeep(memStore);
        if(active) syncRedis(memStore);
        return when(true);
      });
    }

    // else memStore has not changed...
    else {
      return when(true)
        .delay(syncInterval)
        .then(() => {
          if(active) syncRedis(memStore);
          return when(true);
        });
    }
  }
function syncRedis() {
    // if memStore has changed...
    if(JSON.stringify(memCache) !== JSON.stringify(memStore)) {
      return when.promise((resolve, reject) => {
        var serializedStore = JSON.stringify(memStore);
        redis.set(name, serializedStore, err => {
          if(err) {
            reject(err);
          } else {
            resolve(true);
          }
        });
      })
      .delay(syncInterval)
      .catch(err => {
        console.log(err.stack);
        return when(true);
      })
      .finally(() => {
        memCache = _.cloneDeep(memStore);
        if(active) syncRedis(memStore);
        return when(true);
      });
    }

    // else memStore has not changed...
    else {
      return when(true)
        .delay(syncInterval)
        .then(() => {
          if(active) syncRedis(memStore);
          return when(true);
        });
    }
  }
function syncRedis ( ) { // if memStore has changed... if ( JSON . stringify ( memCache ) !== JSON . stringify ( memStore ) ) { return when . promise ( ( resolve , reject ) => { var serializedStore = JSON . stringify ( memStore ) ; redis . set ( name , serializedStore , err => { if ( err ) { reject ( err ) ; } else { resolve ( true ) ; } } ) ; } ) . delay ( syncInterval ) . catch ( err => { console . log ( err . stack ) ; return when ( true ) ; } ) . finally ( ( ) => { memCache = _ . cloneDeep ( memStore ) ; if ( active ) syncRedis ( memStore ) ; return when ( true ) ; } ) ; } // else memStore has not changed... else { return when ( true ) . delay ( syncInterval ) . then ( ( ) => { if ( active ) syncRedis ( memStore ) ; return when ( true ) ; } ) ; } }
start periodicly sync of memStore state to redis
start periodicly sync of memStore state to redis