phalcon 一些开发注意事项和redis配置

开发注意事项

  • 关于命名空间,须要在loader中加载命名空间,如 services目录中,有Auth类。

·loader.php :php

'App\Service'=>'../app/services';redis

  • Auth类中添加命名空间

namespace App\Serviceapp

  • 引入命名空间

use App\Service\Auththis

  • Redis配置

·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);
}

} `

相关文章
相关标签/搜索