2015-02-05 61 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正在運行的服務器和端口。