Skip to content

Commit 43ac3cb

Browse files
authored
Merge pull request #2 from seregazhuk/update-for-react-cache-0.5
Update for reactphp/cache 0.5
2 parents a66bd77 + 680adfc commit 43ac3cb

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
6-
- 7.1
74
- 7.2
85

96
services:

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ $cache = new Memcached($loop);
3535
// store
3636
$cache->set('key', 12345);
3737

38+
// store for a minute
39+
$cache->set('key', 12345, 60);
40+
3841
// retrieve
3942
$cache->get('key')->then(function($value){
4043
// handle data
4144
});
4245

4346
// ...
4447

45-
// remove
46-
$cache->remove('key');
48+
// delete
49+
$cache->delete('key');
4750

4851
$loop->run();
4952
```

composer.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.6",
20-
"react/cache": "^0.4.1",
21-
"seregazhuk/react-memcached": "0.1.4"
19+
"php": ">=7.2",
20+
"seregazhuk/react-memcached": "^0.2"
2221
},
2322
"autoload": {
2423
"psr-4": {
@@ -31,7 +30,6 @@
3130
}
3231
},
3332
"require-dev": {
34-
"seregazhuk/react-promise-testing": "0.*",
35-
"phpunit/phpunit": "~5.0"
33+
"seregazhuk/react-promise-testing": "0.2"
3634
}
3735
}

src/Memcached.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,30 @@ public function __construct(LoopInterface $loop, $address = 'localhost:11211', $
3333

3434
/**
3535
* @param string $key
36+
* @param null|mixed $default
3637
* @return PromiseInterface
3738
*/
38-
public function get($key)
39+
public function get($key, $default = null): PromiseInterface
3940
{
4041
return $this->client->get($this->prefix . $key);
4142
}
4243

43-
4444
/**
4545
* @param string $key
4646
* @param mixed $value
47+
* @param null|int $ttl
4748
* @return PromiseInterface
4849
*/
49-
public function set($key, $value)
50+
public function set($key, $value, $ttl = null): PromiseInterface
5051
{
51-
return $this->client->set($this->prefix . $key, $value);
52+
return $this->client->set($this->prefix . $key, $value, 0, $ttl ?: 0);
5253
}
5354

5455
/**
5556
* @param string $key
5657
* @return PromiseInterface
5758
*/
58-
public function remove($key)
59+
public function delete($key): PromiseInterface
5960
{
6061
return $this->client->delete($this->prefix . $key);
6162
}

tests/CacheTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
class CacheTest extends TestCase
1010
{
11-
/**
12-
* @var Memcached
13-
*/
14-
protected $cache;
11+
private $cache;
1512

1613
protected function setUp()
1714
{
@@ -20,24 +17,24 @@ protected function setUp()
2017
}
2118

2219
/** @test */
23-
public function it_stores_and_retrieves_values()
20+
public function it_stores_and_retrieves_values(): void
2421
{
2522
$this->waitForPromise($this->cache->set('key', 'test'));
2623

2724
$this->assertPromiseFulfillsWith($this->cache->get('key'), 'test');
2825
}
2926

3027
/** @test */
31-
public function it_rejects_promise_when_retrieving_non_existing_key()
28+
public function it_rejects_promise_when_retrieving_non_existing_key(): void
3229
{
3330
$this->assertPromiseRejectsWith($this->cache->get('non-existing-key'), Exception::class);
3431
}
3532

3633
/** @test */
37-
public function it_removes_value_by_key()
34+
public function it_removes_value_by_key(): void
3835
{
3936
$this->waitForPromise($this->cache->set('key-to-remove', 'test'));
40-
$this->cache->remove('key-to-remove');
37+
$this->cache->delete('key-to-remove');
4138
$this->assertPromiseRejectsWith($this->cache->get('key-to-remove'), Exception::class);
4239
}
4340
}

0 commit comments

Comments
 (0)