·loader.php :php
'App\Service'=>'../app/services';
redis
namespace App\Service
app
use App\Service\Auth
this
·services.phpspa
` $di->setShared("redis", function(){ #$frontCache = new FrontendData(["lifetime" => 86400]); $cache = new \Redis(); $config = $this->getConfig(); $cache->connect( $config->redis->host, $config->redis->port ); return $cache; } );code
`開發
·config.phpget
'redis' => [ 'prefix' => '', "host" => "127.0.0.1", "port" => 6379, 'lifetime'=>172800, "auth" => "", ],
·/services/useRedis.php 使用redis的參考類it
` class UseRedis {io
protected $redis = null; public function __construct($redis = null) { $this->redis =$this->initRedis(); } protected function initRedis(){ $di = \Phalcon\Di::getDefault();; $redis = $di['redis']; return $redis; } public function set($key , $value, $expire) { $this->redis->setex($key,$expire,$value); } public function get($key) { return $this->redis->get($key); }
} `