diff --git a/.travis.yml b/.travis.yml index 6fc7c89..f13c2b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,5 @@ env: - HHVM_VERSION=latest install: - docker pull hhvm/hhvm:$HHVM_VERSION - - docker pull redis:5.0-alpine script: - - docker network create testing-network - - docker run --name redis --network testing-network - - docker run --name hhvm --rm -w /var/source -v $(pwd):/var/source hhvm/hhvm:$HHVM_VERSION ./.travis.sh + - docker run --rm -w /var/source -v $(pwd):/var/source hhvm/hhvm:$HHVM_VERSION ./.travis.sh diff --git a/README.md b/README.md index 1ef4cea..4c9a0c4 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ $ hhvm -d xdebug.enable=0 -d hhvm.jit=0 -d hhvm.php7.all=1\ ## Usage -*supported apc, memcached, redis, map, void, filesystem* +*supported apc, memcached, map, void, filesystem* ### Using the CacheManager @@ -183,17 +183,3 @@ $mc->addServers([['127.0.0.1', 11211]]); $cache->setMemcached($mc); $cache->save("qwerty", new Element('testing:cache', 0)); ``` - -#### RedisCache - -```hack -connect('127.0.0.1', 6379); -$cache->setRedis($redis); -$cache->save("qwerty", new Element('testing:cache', 0)); -``` diff --git a/src/CacheManager.hack b/src/CacheManager.hack index 3055435..61c7185 100644 --- a/src/CacheManager.hack +++ b/src/CacheManager.hack @@ -25,7 +25,6 @@ class CacheManager { 'map' => \Nazg\HCache\Driver\MapCache::class, 'file' => \Nazg\HCache\Driver\FileSystemCache::class, 'memcached' => \Nazg\HCache\Driver\MemcachedCache::class, - 'redis' => \Nazg\HCache\Driver\RedisCache::class, }; protected Map $userCache = Map{}; diff --git a/src/Driver/RedisCache.hack b/src/Driver/RedisCache.hack deleted file mode 100644 index b55aea8..0000000 --- a/src/Driver/RedisCache.hack +++ /dev/null @@ -1,71 +0,0 @@ -/** - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This software consists of voluntary contributions made by many individuals - * and is licensed under the MIT license. - * - * Copyright (c) 2017-2019 Yuuki Takezawa - * - */ -namespace Nazg\HCache\Driver; - -use type Redis; -use type Nazg\HCache\Element; -use type Nazg\HCache\CacheProvider; - -class RedisCache extends CacheProvider { - - protected ?Redis $redis; - - public function setRedis(Redis $redis): void { - $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); - $this->redis = $redis; - } - - public function getRedis(): Redis { - invariant( - $this->redis instanceof Redis, - "Type mismatch" - ); - return $this->redis; - } - - <<__Override>> - public function fetch(string $id): mixed { - $element = $this->getRedis()->get($id); - if($element instanceof Element) { - return $element->getData(); - } - return; - } - - <<__Override>> - public function contains(string $id): bool { - return $this->getRedis()->exists($id); - } - - <<__Override>> - public function save(string $id, Element $element): bool { - $lifeTime = $element->getLifetime(); - if ($lifeTime > 0) { - return $this->getRedis()->setex($id, $lifeTime, $element); - } - return $this->getRedis()->set($id, $element); - } - - <<__Override>> - public function delete(string $id): bool { - return $this->getRedis()->delete($id) >= 0; - } - - <<__Override>> - public function flushAll(): bool { - return $this->getRedis()->flushDB(); - } -} diff --git a/src/Element.hack b/src/Element.hack index 33df35a..9c1b4b5 100644 --- a/src/Element.hack +++ b/src/Element.hack @@ -23,10 +23,12 @@ class Element { protected int $lifetime = 0 ) { } + <<__Rx>> public function getData(): mixed { return $this->data; } + <<__Rx>> public function getLifetime(): int { return $this->lifetime; } diff --git a/tests/CacheManagerTest.hack b/tests/CacheManagerTest.hack index 6822513..ef74a7a 100644 --- a/tests/CacheManagerTest.hack +++ b/tests/CacheManagerTest.hack @@ -22,7 +22,6 @@ final class CacheManagerTest extends HackTest { expect($manager->createCache('file'))->toBeInstanceOf(FileSystemCache::class); expect($manager->createCache('apc'))->toBeInstanceOf(ApcCache::class); expect($manager->createCache('memcached'))->toBeInstanceOf(MemcachedCache::class); - expect($manager->createCache('redis'))->toBeInstanceOf(RedisCache::class); expect($manager->createCache('void'))->toBeInstanceOf(VoidCache::class); } diff --git a/tests/Driver/RedisCacheTest.hack b/tests/Driver/RedisCacheTest.hack deleted file mode 100644 index c16bd4a..0000000 --- a/tests/Driver/RedisCacheTest.hack +++ /dev/null @@ -1,35 +0,0 @@ -use type Redis; -use function Facebook\FBExpect\expect; -use type Facebook\HackTest\HackTest; -use type Nazg\HCache\Element; -use type Nazg\HCache\Driver\RedisCache; - -class RedisCacheTest extends HackTest { - - public function testFetchShouldReturnNull(): void { - expect(() ==> { - $cache = new RedisCache(); - expect($cache->fetch("qwerty"))->toBeNull(); - })->toThrow(\HH\InvariantException::class); - } - - public function testFetchShouldReturnNull2(): void { - $cache = new RedisCache(); - $redis = new Redis(); - $redis->connect('redis', 6379); - $cache->setRedis($redis); - $cache->save("qwerty", new Element('testing:cache', 0)); - expect($cache->fetch("qwerty"))->toBeSame('testing:cache'); - expect($cache->fetch("qwerty"))->toBeSame('testing:cache'); - $cache->delete("qwerty"); - expect($cache->fetch("qwerty"))->toBeNull(); - $cache->save("qwerty", new Element('testing:cache', 5)); - expect($cache->fetch("qwerty"))->toBeSame('testing:cache'); - sleep(7); - expect($cache->fetch("qwerty"))->toBeNull(); - - $cache->save("qwerty", new Element('testing:cache', 0)); - $cache->flushAll(); - expect($cache->fetch("qwerty"))->toBeNull(); - } -}