2015-02-05 151 views
0

我想使用redis作为我的缓存引擎,我迄今为止能够在cakephp中添加redis,它将我的会话写入我的redis就好了。这是我在核心cakephp除了会话redis存储

$engine = 'Redis'; 

$prefix = 'myapp_'; 

Cache::config('session', array(
    'engine' => $engine, 
    'prefix' => $prefix . 'cake_session_', 
    'duration' => $duration 
)); 

Configure::write('Session', array(
    'defaults' => 'cache', 
    'timeout' => 100, 
    'start' => true, 
    'checkAgent' => false, 
    'handler' => array(
     'config' => 'session' 
    ) 
)); 

现在我希望能够写从我的控制器Redis的一些缓存的查询做了,但我不能保存在Redis的。相反,它将其保存到一些默认值(我不知道在哪里)缓存。

这是我在我的控制器做

public function index() 
    { 
     Cache::write("TestKey","myquery","default"); 
     var_dump(Cache::read("TestKey")); die;  
    } 

上面给我上的浏览器的值更改为MyQuery但是当我去我的Redis,CLI和查找键*我没有看到那个键有。所以很明显,它拯救了别的地方。我不知道如何写入redis。我试过这个Cache :: write(“TestKey”,“myquery”,“Redis”);但这也没有奏效。 感谢您的帮助提前

**编辑** 1

我只是做了一些调试,它看起来像它试图添加到文件

object(FileEngine)[3] 
    protected '_File' => null 
    public 'settings' => 
    array (size=10) 
     'engine' => string 'File' (length=4) 
     'path' => string '/Library/WebServer/Documents/phoneapp_backend/app/tmp/cache/' (length=60) 
     'prefix' => string 'cake_' (length=5) 
     'lock' => boolean true 
     'serialize' => boolean true 
     'isWindows' => boolean false 
     'mask' => int 436 
     'duration' => int 3600 
     'probability' => int 100 
     'groups' => 
     array (size=0) 
      empty 
    protected '_init' => boolean true 
    protected '_groupPrefix' => null 

我如何改变它写Redis的?

感谢

回答

2

您需要配置default缓存配置中使用文件的Redis的insteado。在app/Config/bootstrap.php变化

Cache::config('default', array('engine' => 'File')); 

,所以它读取:

Cache::config('default', array('engine' => 'Redis')); 

您可能需要更多的选项添加到配置用于指定其中的Redis正在运行的服务器和端口。