我尝试使用CakePHP3与Redis

步驟

安装(CentOS6.6)

yum -y install redis
yum -y install  --enablerepo=remi --enablerepo=remi-php70 php-redis

修改php.ini文件

extension=redis.so

重新启动Apache和启动Redis服务器。

sudo service httpd restart
redis-server

将CakePHP3的缓存修正为Redis。

         'default' => [
             'className' => 'Redis',
             'prefix' => 'shinderuman_', // defaultは'cake_'
         ],

实施

简单的键值对

         $key = 'bar';
         $foo = 'abc';
         Cache::write($key, $foo);
         $cache = Cache::read($key);
         var_dump($cache); // 'abc'

我想知道SimpleXMLElement是否能够保存。

         $key = 'foo';
         $xml = '<?xml version="1.0" encoding="utf-8"?><project name="hogehoge" default="hogehoge"></project>';
         $foo = new \SimpleXMLElement($xml);
         Cache::write($key, $foo); // やっぱりserializeしようとして怒られるorz(Serialization of 'SimpleXMLElement' is not allowed)

尝试从 cli 中进行获取。

~% redis-cli
redis 127.0.0.1:6379> get shinderuman_bar
"s:3:\"abc\";"
redis 127.0.0.1:6379> get shinderuman_foo
(nil) // 当然いない

请参阅相关资料。

    • Caching — CakePHP Cookbook 3.x documentation http://book.cakephp.org/3.0/en/core-libraries/caching.html

ElastiCacheでRedisをサポートしたのでCakePHPから使ってみた – Qiita http://qiita.com/uda0922/items/a8a9760a4476adb3d88a