1. redis 配置
1.1 连接 框架本身
use Phalcon\Cache\Backend\Redis;
use Phalcon\Cache\Frontend\Data as FrontData;
$di->set('modelsCache', function () {
$frontCache = new FrontData(["lifetime" => 120,]);
$cache = new Redis(
$frontCache,
[
'prefix' => 'bixiang',
'lifettime' => 120,
'host' => '127.0.0.1',
'port' => 6379,
'persistent' => false
]
);
return $cache;
});
$this->modelsCache->save('qwe',1234);
$this->modelsCache->get('qwe');
1.2 连接自己写的类
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\DiInterface;
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();
$loader->registerNamespaces(
[
'Apps\Frontend\Controllers' => '../apps/frontend/controllers/',
'Apps\Frontend\Models' => '../apps/frontend/models/',
'Apps\Library' => '../apps/library/',
'Apps\Plugins' => '../apps/plugins/',
]
);
$loader->register();
}
注意: 命名空间
namespace Redis;
$Redis = new \Redis\RedisHelp();
$Redis->set("test",9999);
echo $Redis->get("testa");exit;