Skip to content

Commit e94dd67

Browse files
committed
init
0 parents  commit e94dd67

10 files changed

+298
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
composer.lock
3+

.gush.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Gush configuration file, any comments will be lost.
2+
repo_adapter: github
3+
issue_tracker: github
4+
repo_org: php-cache
5+
repo_name: phpredis-adapter
6+
issue_project_org: php-cache
7+
issue_project_name: phpredis-adapter
8+
meta-header: "This file is part of php-cache\\phpredis-adapter package.\n\n(c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]> \n\nThis source file is subject to the MIT license that is bundled\nwith this source code in the file LICENSE."
9+
pr_type:
10+
- feature
11+
- bugfix
12+
- refactor
13+
- tests
14+
- remove
15+
- style
16+
- documentation
17+
- security
18+
table-pr:
19+
fixed_tickets: ['Fixed Tickets', '']

.travis.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
language: php
2+
php:
3+
- "7.0"
4+
- "5.6"
5+
- "5.5"
6+
7+
services:
8+
- phpredis-server
9+
10+
matrix:
11+
fast_finish: true
12+
13+
before_install:
14+
- phpenv config-rm xdebug.ini
15+
- pip install --user codecov
16+
17+
before_script:
18+
- travis_retry composer self-update
19+
- travis_retry composer install --prefer-source --no-interaction
20+
21+
script:
22+
- php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-clover=coverage.xml
23+
24+
after_success:
25+
- codecov

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Aaron Scherer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# PhpRedis PSR-6 adapter
2+
[![Build Status](https://travis-ci.org/php-cache/phpredis-adapter.svg?branch=master)](https://travis-ci.org/php-cache/phpredis-adapter) [![codecov.io](https://codecov.io/github/php-cache/phpredis-adapter/coverage.svg?branch=master)](https://codecov.io/github/php-cache/phpredis-adapter?branch=master)
3+
4+
This is a implementation for the PSR-6 for PhpRedis cache. This implementation supports tags.
5+
6+
This implementation is using [PhpRedis](https://github.com/phpredis/phpredis). If you want an adapter with
7+
[Predis](https://github.com/nrk/predis) you should look at our [Redis adapter](https://github.com/php-cache/redis-adapter).

composer.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "cache/phpredis-adapter",
3+
"description": "A PSR-6 cache implementation using Redis (PhpRedis). This implementation supports tags",
4+
"type": "library",
5+
"license": "MIT",
6+
"minimum-stability": "stable",
7+
"keywords":
8+
[
9+
"cache",
10+
"psr-6",
11+
"phpredis",
12+
"redis",
13+
"tag"
14+
],
15+
"homepage": "https://github.com/php-cache/phpredis-adapter",
16+
"authors":
17+
[
18+
{
19+
"name": "Aaron Scherer",
20+
"email": "[email protected]",
21+
"homepage": "https://github.com/aequasi"
22+
},
23+
{
24+
"name": "Tobias Nyholm",
25+
"email": "[email protected]",
26+
"homepage": "https://github.com/nyholm"
27+
}
28+
],
29+
"require":
30+
{
31+
"php": "^5.5|^7.0",
32+
"ext-redis": "*",
33+
"psr/cache": "1.0.0",
34+
"cache/adapter-common": "^0.1.2",
35+
"cache/taggable-cache": "^0.2"
36+
},
37+
"require-dev":
38+
{
39+
"phpunit/phpunit": "^5.1|^4.0",
40+
"cache/integration-tests": "dev-master"
41+
},
42+
"provide":
43+
{
44+
"psr/cache-implementation": "1.0.0"
45+
},
46+
"autoload":
47+
{
48+
"psr-4": {
49+
"Cache\\Adapter\\PhpRedis\\": "src/"
50+
}
51+
},
52+
"autoload-dev":
53+
{
54+
"psr-4": {
55+
"Cache\\Adapter\\PhpRedis\\Tests\\": "tests/"
56+
}
57+
}
58+
}

phpunit.xml.dist

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="vendor/autoload.php"
13+
>
14+
<testsuites>
15+
<testsuite name="Main Test Suite">
16+
<directory>./tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<logging>
21+
<log type="coverage-text" target="php://stdout"/>
22+
<log type="coverage-html" target="./coverageReport"/>
23+
</logging>
24+
25+
<groups>
26+
<exclude>
27+
<group>benchmark</group>
28+
</exclude>
29+
</groups>
30+
31+
<filter>
32+
<whitelist>
33+
<directory>src/</directory>
34+
</whitelist>
35+
</filter>
36+
</phpunit>

src/PhpRedisCachePool.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\phpredis-adapter package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\Adapter\PhpRedis;
13+
14+
use Cache\Adapter\Common\AbstractCachePool;
15+
use Psr\Cache\CacheItemInterface;
16+
17+
/**
18+
* @author Tobias Nyholm <[email protected]>
19+
*/
20+
class PhpRedisCachePool extends AbstractCachePool
21+
{
22+
/**
23+
* @type \Redis
24+
*/
25+
private $cache;
26+
27+
/**
28+
* @param \Redis $cache
29+
*/
30+
public function __construct(\Redis $cache)
31+
{
32+
$this->cache = $cache;
33+
}
34+
35+
protected function fetchObjectFromCache($key)
36+
{
37+
return unserialize($this->cache->get($key));
38+
}
39+
40+
protected function clearAllObjectsFromCache()
41+
{
42+
return $this->cache->flushDb();
43+
}
44+
45+
protected function clearOneObjectFromCache($key)
46+
{
47+
return $this->cache->del($key) >= 0;
48+
}
49+
50+
protected function storeItemInCache($key, CacheItemInterface $item, $ttl)
51+
{
52+
if ($ttl === null) {
53+
return $this->cache->set($key, serialize($item));
54+
}
55+
56+
return $this->cache->setex($key, $ttl, serialize($item));
57+
}
58+
}

tests/IntegrationPoolTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\phpredis-adapter package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\Adapter\PhpRedis\Tests;
13+
14+
use Cache\Adapter\PhpRedis\PhpRedisCachePool;
15+
use Cache\IntegrationTests\CachePoolTest as BaseTest;
16+
17+
class IntegrationPoolTest extends BaseTest
18+
{
19+
private $client = null;
20+
21+
public function createCachePool()
22+
{
23+
return new PhpRedisCachePool($this->getClient());
24+
}
25+
26+
private function getClient()
27+
{
28+
if ($this->client === null) {
29+
$this->client = new \Redis();
30+
$this->client->connect('127.0.0.1', 6379);
31+
}
32+
33+
return $this->client;
34+
}
35+
}

tests/IntegrationTagTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache\phpredis-adapter package.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\Adapter\PhpRedis\Tests;
13+
14+
use Cache\Adapter\PhpRedis\PhpRedisCachePool;
15+
use Cache\IntegrationTests\TaggableCachePoolTest;
16+
17+
class IntegrationTagTest extends TaggableCachePoolTest
18+
{
19+
private $client = null;
20+
21+
public function createCachePool()
22+
{
23+
return new PhpRedisCachePool($this->getClient());
24+
}
25+
26+
private function getClient()
27+
{
28+
if ($this->client === null) {
29+
$this->client = new \Redis();
30+
$this->client->connect('127.0.0.1', 6379);
31+
}
32+
33+
return $this->client;
34+
}
35+
}

0 commit comments

Comments
 (0)