| @@ 17-25 (lines=9) @@ | ||
| 14 | $this->redis = $redis; |
|
| 15 | } |
|
| 16 | ||
| 17 | public function increment(string $key): Promise { |
|
| 18 | return \Amp\resolve(function() use ($key) { |
|
| 19 | try { |
|
| 20 | return yield $this->redis->incr($key); |
|
| 21 | } catch (RedisException $e) { |
|
| 22 | throw new StorageFailedException('Failed to increment counter.', 0, $e); |
|
| 23 | } |
|
| 24 | }); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function decrement(string $key): Promise { |
|
| 28 | return \Amp\resolve(function() use ($key) { |
|
| @@ 27-35 (lines=9) @@ | ||
| 24 | }); |
|
| 25 | } |
|
| 26 | ||
| 27 | public function decrement(string $key): Promise { |
|
| 28 | return \Amp\resolve(function() use ($key) { |
|
| 29 | try { |
|
| 30 | return yield $this->redis->decr($key); |
|
| 31 | } catch (RedisException $e) { |
|
| 32 | throw new StorageFailedException('Failed to decrement counter.', 0, $e); |
|
| 33 | } |
|
| 34 | }); |
|
| 35 | } |
|
| 36 | ||
| 37 | public function get(string $key): Promise { |
|
| 38 | return \Amp\resolve(function() use ($key) { |
|
| @@ 49-57 (lines=9) @@ | ||
| 46 | }); |
|
| 47 | } |
|
| 48 | ||
| 49 | public function set(string $key, int $val): Promise { |
|
| 50 | return \Amp\resolve(function() use ($key, $val) { |
|
| 51 | try { |
|
| 52 | return yield $this->redis->set($key, $val); |
|
| 53 | } catch (RedisException $e) { |
|
| 54 | throw new StorageFailedException('Failed to set counter value.', 0, $e); |
|
| 55 | } |
|
| 56 | }); |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||
| 60 | ||