public function limitRate($key) { if (!$this->client->hexists($key, 'limit')) { return false; } $this->client->hincrby($key, 'calls', 1); return $this->getRateInfo($key); }
/** * 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; }
/** * @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); }
/** * @param $increment * @param $email * @return int */ protected function throttleEmail($increment, $email) { return $this->redis->hincrby($this->key('email'), $email, $increment ? 1 : -1); }