mirror of
https://github.com/Mactronique/phpcache.git
synced 2026-03-24 17:02:12 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93ac5d6644 | ||
|
|
f2bdb0af19 | ||
|
|
9c64d7ab2b | ||
|
|
e0077001d3 | ||
|
|
25367c1296 | ||
|
|
60571a6616 | ||
|
|
5f1d8143e9 |
@@ -1,6 +1,10 @@
|
||||
# phpcache
|
||||
|
||||
[](https://travis-ci.org/Mactronique/phpcache)
|
||||
[](https://www.versioneye.com/user/projects/55c2676e653762001a00287f)
|
||||
[](https://packagist.org/packages/mactronique/phpcache)
|
||||
[](https://packagist.org/packages/mactronique/phpcache)
|
||||
[](https://packagist.org/packages/mactronique/phpcache)
|
||||
|
||||
## Supported driver
|
||||
|
||||
|
||||
@@ -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,14 @@ 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 (null !== $database) {
|
||||
|
||||
Reference in New Issue
Block a user