Skip to content

Commit

Permalink
Minor refactor of flush method
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Azzolini committed Jul 1, 2016
1 parent 2c8a3f4 commit 278cd92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 0 additions & 8 deletions bundle.php

This file was deleted.

16 changes: 9 additions & 7 deletions classes/Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* Core\Cache Redis Driver.
*
* @package core
* @author stefano.azzolini@caffeinalab.com
* @version 1.0
* @copyright Caffeina srl - 2014 - http://caffeina.co
* @author stefano.azzolini@caffeina.com
* @author gabriele.diener@caffeina.com
* @version 1.0.1
* @copyright Caffeina srl - 2014-2016 - http://caffeina.com
*/


Expand Down Expand Up @@ -43,7 +44,7 @@ public function __construct($opt=[]){
* https://github.com/nrk/predis
*/
$this->options = array_merge($opt,$this->options);
$this->redis = new \Predis\Client($this->options['scheme'].'://'.$this->options['host'].':'.$this->options['port'].'/',[
$this->redis = new \Predis\Client($this->options['scheme'].'://'.$this->options['host'].':'.$this->options['port'].'/', [
'prefix' => 'core:'.$this->options['prefix'],
'exceptions' => $this->options['exceptions'],
'connection_timeout' => $this->options['timeout'],
Expand All @@ -57,7 +58,7 @@ public function get($key){
}

public function set($key,$value,$expire=0){
$expire ? $this->redis->setex($key,$expire,serialize($value)) : $this->redis->set($key,serialize($value));
return $expire >= 0 ? $this->redis->setex($key,$expire,serialize($value)) : $this->redis->set($key,serialize($value));
}

public function delete($key){
Expand All @@ -69,8 +70,9 @@ public function exists($key){
}

public function flush(){
if (empty($this->redis->keys('*'))) return false;
return call_user_func_array([$this->redis,'eval'], ["return redis.call('del', unpack(redis.call('keys', ARGV[1])))", "0", "*"]);
return $this->redis->keys('*')
? $this->redis->eval("return redis.call('del', unpack(redis.call('keys', ARGV[1])))", "0", "*")
: false;
}

public function inc($key,$value=1){
Expand Down

0 comments on commit 278cd92

Please sign in to comment.