Example #1
0
 public function avg($field)
 {
     $avg = $this->cached('avg' . $field . '.' . sha1(serialize($this->wheres)));
     if (!$avg) {
         $collection = [];
         foreach ($this->cursor as $id) {
             $val = $this->store->hget('row.' . $id, $field);
             if ($val) {
                 $add = ['id' => $id, $field => $val];
                 $collection[] = $add;
             }
         }
         $collection = new Collection($collection);
         $avg = $collection->avg($field);
         $this->setCached('avg' . $field . '.' . sha1(serialize($this->wheres)), $avg);
     }
     return $avg;
 }