11 Commits

Author SHA1 Message Date
Jean-Baptiste Nahan
f675b04591 Update composer.json 2019-04-02 09:16:38 +02:00
Jean-Baptiste Nahan
68072f9008 Update composer.json 2016-11-09 21:05:18 +01:00
Jean-Baptiste Nahan
ddf7b341da Fix #2 2016-09-01 13:29:25 +02:00
macintoshplus
e2de4cdd23 Add auth for redis 2015-10-12 13:42:45 +02:00
macintoshplus
93ac5d6644 fix type 2015-10-08 10:19:44 +02:00
macintoshplus
f2bdb0af19 fix set 2015-09-24 14:01:05 +02:00
macintoshplus
9c64d7ab2b fix set 2015-09-24 13:51:26 +02:00
macintoshplus
e0077001d3 fix exist 2015-09-24 09:53:11 +02:00
macintoshplus
25367c1296 fix class name 2015-09-24 09:39:56 +02:00
Jean-Baptiste Nahan
60571a6616 Update README.md 2015-08-05 22:09:43 +02:00
Jean-Baptiste Nahan
5f1d8143e9 Update README.md 2015-08-05 21:49:41 +02:00
4 changed files with 38 additions and 20 deletions

View File

@@ -1,6 +1,10 @@
# phpcache
[![Build Status](https://travis-ci.org/Mactronique/phpcache.svg?branch=master)](https://travis-ci.org/Mactronique/phpcache)
[![Dependency Status](https://www.versioneye.com/user/projects/55c2676e653762001a00287f/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55c2676e653762001a00287f)
[![Latest Stable Version](https://poser.pugx.org/mactronique/phpcache/v/stable)](https://packagist.org/packages/mactronique/phpcache)
[![Latest Unstable Version](https://poser.pugx.org/mactronique/phpcache/v/unstable)](https://packagist.org/packages/mactronique/phpcache)
[![License](https://poser.pugx.org/mactronique/phpcache/license)](https://packagist.org/packages/mactronique/phpcache)
## Supported driver

View File

@@ -6,12 +6,11 @@
"authors": [
{
"name": "Jean-Baptiste Nahan",
"email": "jbnahan@gmail.com"
"email": "macintoshplus@users.noreply.github.com"
}
],
"require": {
"php": ">=5.4",
"jms/serializer": "~1.0"
"php": ">=5.4"
},
"require-dev": {
"atoum/atoum": "master-dev"
@@ -31,5 +30,6 @@
"branch-alias": {
"dev-master": "1.x-dev"
}
}
},
"abandoned": "psr/simple-cache"
}

View File

@@ -21,10 +21,10 @@ class RedisDriver implements Driver
public function checkDriver()
{
if (!class_exists('Redis')) {
throw new DriverRequirementFailException("Redis extension not installed", self::NAME);
throw new DriverRequirementFailException('Redis extension not installed', self::NAME);
}
}
/**
* @return string Driver name
*/
@@ -35,6 +35,7 @@ class RedisDriver implements Driver
/**
* @param string $key
*
* @return mixed
*/
public function get($key)
@@ -43,31 +44,38 @@ class RedisDriver implements Driver
$value = $this->client->get($key);
if ($value == false) {
return null;
return;
}
return $value;
}
/**
* @param string $key
* @param mixed $value
* @param integer $ttl
* @param mixed $value
* @param int $ttl
*
* @return mixed
*/
public function set($key, $value, $ttl = null)
{
$this->connectServer();
return $this->client->set($keyword, $value, (null === $ttl)? 0:$ttl);
$this->client->set($key, $value);
if (null !== $ttl) {
$this->client->setTimeout($key, $ttl);
}
}
/**
* @param string $key
* @return boolean
*
* @return bool
*/
public function exists($key)
{
$this->connectServer();
return (null !== $this->client->exists($key));
return $this->client->exists($key);
}
/**
@@ -76,16 +84,18 @@ class RedisDriver implements Driver
public function remove($key)
{
$this->connectServer();
return $this->client->delete($key);
}
/**
* Remove all keys and value from cache
* Remove all keys and value from cache.
*/
public function clean()
{
$this->connectServer();
$this->client->flushDB();
return true;
}
@@ -93,14 +103,18 @@ class RedisDriver implements Driver
{
if (null === $this->client) {
$host = $this->config['host'];
$port = array_key_exists('port', $this->config)? (int)$this->config['port']:6379;
$password = (array_key_exists('password', $this->config))? $this->config['password']:'';
$database = (array_key_exists('database', $this->config)? (int)$this->config['database']:null);
$timeout = (array_key_exists('timeout', $this->config))? (int)$this->config['timeout']:1;
$port = array_key_exists('port', $this->config) ? (int) $this->config['port'] : 6379;
$password = (array_key_exists('password', $this->config)) ? $this->config['password'] : '';
$database = (array_key_exists('database', $this->config) ? (int) $this->config['database'] : null);
$timeout = (array_key_exists('timeout', $this->config)) ? (int) $this->config['timeout'] : 1;
$this->client = new Redis();
$this->client = new \Redis();
if (!$this->client->connect($host, $port, $timeout)) {
throw new ServerException("Error Unable to connect to server");
throw new ServerException('Error Unable to connect to server');
}
if (!empty($password)) {
$this->client->auth($password);
}
if (null !== $database) {

View File

@@ -51,7 +51,7 @@ class PhpCache
*/
public function set($key, $value, $ttl = null, $driverName = null)
{
return $this->getDriver($driverName)->set($key, $value, $ttl = null);
return $this->getDriver($driverName)->set($key, $value, $ttl);
}
/**