title: Redis server went away always at specific point in app
body: <p>So we've been modifying our app to use Redis to cache some results of our ORM (custom built) and so far it seemed like it was working perfectly well until we hit a point where it always crashes on us giving us back the "RedisException: Redis server went away" with oh soooo much information to work with :)</p>
  
  <p>We've been going through logs (docker and verbose redis.log) to find out what is happening to no avail. What we know:</p>
  
  <ul>
  <li>The problem happens not because of data but when trying to SET or EXIST with a specific key.</li>
  <li>It is always the same exact point in the app, we can refresh the page and it always crashes at that one specific point in the code</li>
  <li>The key can be MD5'ed, SHA'ed or the natural key we built from ORM data it always crashes.</li>
  <li>We thought it might be the amount of calls sent to redis (yeah right) but even after removing all EXIST calls to redis and just using GET and handling exceptions or null values ourselves internally, the error still pops EXACTLY at that one point.</li>
  <li>The server doesn't go away for real, the docker process is still up, the process in it still runs</li>
  <li>Using "redis-cli monitor" gives us a nice log of what goes through, everything does get logged to it up to that point + the php session_save_handler that saves stuff to redis (gone away, right, you accept to save the session just after the error heh)</li>
  <li>Looking in a "verbose" customized docker redis log in "/var/log/redis.log" yields NO ERROR :(</li>
  <li>Using redis-cli to set the key ourselves from the command line works, both with the MD5'ed, SHA'ed or naturally composed keys...</li>
  </ul>
  
  <p>We're really running out of options here, here is some more information such as code so you have an idea what is happening, some help would trully be appreciated at that point:</p>
  
  <p><strong>More info</strong></p>
  
  <pre><code> Docker architecture
   PHP7.0 latest build
   Redis latest build from official repo on docker
  </code></pre>
  
  <p><strong>RedisCache.php</strong></p>
  
  <pre><code>/**
   * Standard Redis object coming from php-redis extension
   * @var \Redis
   */
  protected $redis;
  
  public function offsetExists($offset)
  {
      try {
          return $this-&gt;redis-&gt;exists($offset); //&lt;-- Fails here
      } catch (\RedisException $ex) {
          return false;
      }
  }
  
  public function offsetSet($offset, $value)
  {
      $this-&gt;redis-&gt;set($offset, serialize($value)); //&lt;-- Fails here
      $this-&gt;redis-&gt;expire($offset, 60 * 60);
  }
  </code></pre>
  
  <p><strong>client.api.php</strong></p>
  
  <pre><code>public static function getCachedRecords(
      $endPoint,
      $data = [],
      $asArray = false,
      \LearningBird\Cache\BaseCache $cache
  ) {
      $key = 'api:' . md5(($asArray ? 'asArray' : '') . ':' . serialize([$endPoint, $data]));
      try {
          $data = $cache[$key];
      } catch (\Exceptions\Data\NotFoundException $ex) {
          $cache[$key] = $data = self::getRecords($endPoint, $data, $asArray);
      }
  
      return $data;
  }
  </code></pre>
  
  <hr>
  
  <p>** Edit #1 - Stacktrace + examples of keys that work and don't**</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Cache/RedisCache.php
          [line] =&gt; 64
          [function] =&gt; get
          [class] =&gt; Redis
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; api:4a23b037c2ff882924db6974a665b12a
              )
  
      )
  
  [1] =&gt; Array
      (
          [file] =&gt; /var/www/feather/dataExchange/api.learningbird.com/client.api.php
          [line] =&gt; 262
          [function] =&gt; offsetGet
          [class] =&gt; LearningBird\Cache\RedisCache
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; api:4a23b037c2ff882924db6974a665b12a
              )
  
      )
  
  [2] =&gt; Array
      (
          [file] =&gt; /var/www/feather/classes/mvc/models/topicsRecord.php
          [line] =&gt; 167
          [function] =&gt; getCachedRecords
          [class] =&gt; apiClient
          [type] =&gt; ::
          [args] =&gt; Array
              (
                  [0] =&gt; /topics/getParentSuperTopics/4196
                  [1] =&gt; Array
                      (
                      )
  
                  [2] =&gt; 
                  [3] =&gt; LearningBird\Cache\RedisCache Object
                      (
                          [redis:protected] =&gt; Redis Object
                              (
                                  [socket] =&gt; 0
                              )
  
                      )
  
              )
  
      )
  
  [3] =&gt; Array
      (
          [file] =&gt; /var/www/feather/classes/mvc/models/topicsRecord.php
          [line] =&gt; 177
          [function] =&gt; getParentSuperTopics
          [class] =&gt; topicsRecord
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
              )
  
      )
  
  [4] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
          [line] =&gt; 282
          [function] =&gt; hasParentSuperTopics
          [class] =&gt; topicsRecord
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
              )
  
      )
  
  [5] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
          [line] =&gt; 158
          [function] =&gt; getTopicsWithSuperTopics
          [class] =&gt; LearningBird\Database\Provider\LessonProvider
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; recordSet Object
                      (
                          /** hidden, too large **/
                      )
  
              )
  
      )
  
  [6] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
          [line] =&gt; 86
          [function] =&gt; LearningBird\Database\Provider\{closure}
          [class] =&gt; LearningBird\Database\Provider\LessonProvider
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; recordSet Object
                      (
                          /** hidden, too large **/
                      )
  
              )
  
      )
  
  [7] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Database/Provider/LessonProvider.php
          [line] =&gt; 191
          [function] =&gt; getLessonsFromFilters
          [class] =&gt; LearningBird\Database\Provider\LessonProvider
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [0] =&gt; LearningBird\Database\Provider\LessonProviderFilter Object
                              (
                                  [type:protected] =&gt; lesson
                                  [id:protected] =&gt; 20386
                              )
  
                      )
  
                  [1] =&gt; recordSet Object
                      (
                          /** hidden, too large **/
                      )
  
                  [2] =&gt; Closure Object
                      (
                          /** hidden, too large **/
                      )
  
                  [3] =&gt; 
                  [4] =&gt; Array
                      (
                          /** hidden, too large **/
                      )
  
                  [5] =&gt; Array
                      (
                          [0] =&gt; and
                          [1] =&gt; or
                          [2] =&gt; or
                      )
  
              )
  
      )
  
  [8] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Database/Provider/STDAProvider.php
          [line] =&gt; 82
          [function] =&gt; getSTDALessons
          [class] =&gt; LearningBird\Database\Provider\LessonProvider
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [0] =&gt; LearningBird\Database\Provider\LessonProviderFilter Object
                              (
                                  [type:protected] =&gt; lesson
                                  [id:protected] =&gt; 20386
                              )
  
                      )
  
                  [1] =&gt; topicLessonsRecordSet Object
                      (
                          /** hidden, too large **/
                      )
  
                  [2] =&gt; differentiationsRecordSet Object
                      (
                          [records:protected] =&gt; Array
                              (
                                  /** hidden, too large **/
                              )
  
                      )
  
              )
  
      )
  
  [9] =&gt; Array
      (
          [file] =&gt; /var/www/Classes/LearningBird/Database/Provider/STDAProvider.php
          [line] =&gt; 44
          [function] =&gt; getAllSTDAs
          [class] =&gt; LearningBird\Database\Provider\STDAProvider
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  /** hidden, too large **/
              )
  
      )
  
  [10] =&gt; Array
      (
          [file] =&gt; /var/www/app/application/components/lessons/component.php
          [line] =&gt; 227
          [function] =&gt; getSTDAs
          [class] =&gt; LearningBird\Database\Provider\STDAProvider
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  ** hidden, too large **/
              )
  
      )
  
  [11] =&gt; Array
      (
          [function] =&gt; watch
          [class] =&gt; lessonsController
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  [0] =&gt; dlvi1mywqv6c6sh0
              )
  
      )
  
  [12] =&gt; Array
      (
          [file] =&gt; /var/www/feather/classes/mvc/baseController.php
          [line] =&gt; 221
          [function] =&gt; invokeArgs
          [class] =&gt; ReflectionMethod
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
                  ** hidden, too large **/
              )
  
      )
  
  [13] =&gt; Array
      (
          [file] =&gt; /var/www/feather/classes/mvc/baseController.php
          [line] =&gt; 105
          [function] =&gt; exec
          [class] =&gt; baseController
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
              )
  
      )
  
  [14] =&gt; Array
      (
          [file] =&gt; /var/www/feather/classes/mvc/baseController.php
          [line] =&gt; 89
          [function] =&gt; _run
          [class] =&gt; baseController
          [type] =&gt; -&gt;
          [args] =&gt; Array
              (
              )
  
      )
  
  [15] =&gt; Array
      (
          [file] =&gt; /var/www/feather/classes/component/core.component.php
          [line] =&gt; 43
          [function] =&gt; run
          [class] =&gt; baseController
          [type] =&gt; ::
          [args] =&gt; Array
              (
              )
  
      )
  
  [16] =&gt; Array
      (
          [file] =&gt; /var/www/app/application/webroot/index.php
          [line] =&gt; 170
          [function] =&gt; run
          [class] =&gt; component
          [type] =&gt; ::
          [args] =&gt; Array
              (
                  [0] =&gt; lessons
              )
  
      )
  
  )
  </code></pre>
  
  <p><strong>Example of keys that work following the same principle</strong></p>
  
  <pre><code>topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"1599";";}";}
  
  gradesModel:a:2:{s:9:"innerJoin";s:7:"s:0:"";";s:5:"where";s:95:"a:1:{s:10:"gradeLevel";s:63:"a:3:{i:0;s:8:"s:1:"9";";i:1;s:8:"s:1:"9";";i:2;s:8:"s:1:"9";";}";}";}
  
  topicsModel:a:2:{s:9:"innerJoin";s:20:"s:12:"topicLessons";";s:5:"where";s:98:"a:2:{s:20:"topicLessons.deleted";s:8:"s:1:"0";";s:21:"topicLessons.lessonID";s:12:"s:5:"20386";";}";}
  
  topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"4196";";}";}
  
  languagesModel:a:1:{s:5:"where";s:37:"a:1:{s:9:"statusID!";s:8:"s:1:"0";";}";}
  
  topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"2718";";}";}
  
  differentiationsModel:a:2:{s:9:"innerJoin";s:30:"s:22:"lessonDifferentiations";";s:5:"where";s:65:"a:1:{s:31:"lessonDifferentiations.lessonID";s:12:"s:5:"20386";";}";}
  
  regionsModel:a:1:{s:5:"where";s:66:"a:2:{s:9:"countryID";s:7:"s:0:"";";s:7:"stateID";s:9:"s:2:"79";";}";}
  
  topicsModel:a:2:{s:9:"innerJoin";s:7:"s:0:"";";s:5:"where";s:103:"a:1:{s:7:"topicID";s:75:"a:3:{i:0;s:11:"s:4:"3361";";i:1;s:11:"s:4:"1523";";i:2;s:11:"s:4:"2115";";}";}";}
  
  topicsModel:a:1:{s:5:"where";s:40:"a:1:{s:7:"topicID";s:12:"s:5:"11270";";}";}
  
  topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"1523";";}";}
  
  topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"3361";";}";}
  
  api:b1eb15940ff2c1caca5e51239580c924
  
  topicsModel:a:1:{s:5:"where";s:36:"a:1:{s:4:"slug";s:11:"s:4:"math";";}";}
  
  topicsModel:a:1:{s:5:"where";s:39:"a:1:{s:7:"topicID";s:11:"s:4:"3205";";}";}
  
  differentiationsModel:a:0:{}
  
  stateSchoolStructuresModel:a:1:{s:5:"where";s:36:"a:1:{s:7:"stateID";s:9:"s:2:"79";";}";}
  
  api:5135098ff6e115ec160bb9d552ac9442
  
  statesModel:a:1:{s:5:"where";s:36:"a:1:{s:7:"stateID";s:9:"s:2:"79";";}";}
  
  languagesModel:a:1:{s:5:"where";s:39:"a:1:{s:10:"languageID";s:8:"s:1:"1";";}";}
  
  api:e532b1617c11604e6f5e241fffcc0e27
  </code></pre>
  
  <p>** Keys that don't work (same key, md5'ed or natural) **</p>
  
  <pre><code>api::a:2:{i:0;s:33:"/topics/getParentSuperTopics/4196";i:1;a:0:{}}
  
  4a23b037c2ff882924db6974a665b12a
  </code></pre>