Example #1
0
 public function sum($field)
 {
     $sum = $this->cached('sum' . $field . '.' . sha1(serialize($this->wheres)));
     if (!$sum) {
         $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);
         $sum = $collection->sum($field);
         $this->setCached('sum' . $field . '.' . sha1(serialize($this->wheres)), $sum);
     }
     return $sum;
 }