Example #1
0
 public function limitRate($key)
 {
     if (!$this->client->hexists($key, 'limit')) {
         return false;
     }
     $this->client->hincrby($key, 'calls', 1);
     return $this->getRateInfo($key);
 }
Example #2
0
 /**
  * Add distributed metric.
  *
  * @param EntryInterface $entry    Entry
  * @param string         $entryKey Key entry
  *
  * @return $this Self Object
  */
 private function addDistributedEntry(EntryInterface $entry, $entryKey)
 {
     $this->doRedisQuery(function () use($entry, $entryKey) {
         $this->redis->hincrby($entryKey . '_distr', $entry->getValue(), 1);
     });
     return $this;
 }
Example #3
0
 /**
  * @param string $key
  * @param string $field 计数field
  * @param int $step
  * @param bool $zeroLimit 最小为零限制 限制最小可以自减到 0
  * @return int
  */
 public function htDecrField($key, $field, $step = 1, $zeroLimit = true)
 {
     // fix: not allow lt 0
     if ($zeroLimit && (int) $this->redis->hget($key, $field) <= 0) {
         return 0;
     }
     return $this->redis->hincrby($key, $field, -$step);
 }
Example #4
0
 /**
  * @param $increment
  * @param $email
  * @return int
  */
 protected function throttleEmail($increment, $email)
 {
     return $this->redis->hincrby($this->key('email'), $email, $increment ? 1 : -1);
 }