| @@ 30-43 (lines=14) @@ | ||
| 27 | return $this->createRateInfo($info); |
|
| 28 | } |
|
| 29 | ||
| 30 | public function limitRate($key) |
|
| 31 | { |
|
| 32 | $info = $this->client->get($key); |
|
| 33 | if ($info === null || !array_key_exists('limit', $info)) { |
|
| 34 | return false; |
|
| 35 | } |
|
| 36 | ||
| 37 | $info['calls']++; |
|
| 38 | $ttl = $info['reset'] - time(); |
|
| 39 | ||
| 40 | $this->client->set($key, $info, $ttl); |
|
| 41 | ||
| 42 | return $this->createRateInfo($info); |
|
| 43 | } |
|
| 44 | ||
| 45 | public function createRate($key, $limit, $period) |
|
| 46 | { |
|
| @@ 30-44 (lines=15) @@ | ||
| 27 | return $this->createRateInfo($info); |
|
| 28 | } |
|
| 29 | ||
| 30 | public function limitRate($key) |
|
| 31 | { |
|
| 32 | $info = $this->client->fetch($key); |
|
| 33 | if ($info === false || !array_key_exists('limit', $info)) { |
|
| 34 | return false; |
|
| 35 | } |
|
| 36 | ||
| 37 | $info['calls']++; |
|
| 38 | ||
| 39 | $expire = $info['reset'] - time(); |
|
| 40 | ||
| 41 | $this->client->save($key, $info, $expire); |
|
| 42 | ||
| 43 | return $this->createRateInfo($info); |
|
| 44 | } |
|
| 45 | ||
| 46 | public function createRate($key, $limit, $period) |
|
| 47 | { |
|