8 Commits
1.0.1 ... 1.0.3

Author SHA1 Message Date
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
2 changed files with 33 additions and 15 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

@@ -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) {