- redisPool 封装目录结构
├─redis_pool --------- 主目录
│ ├─redis
│ │ ├─RedisOp.php ------ redis操作类
│ │ ├─RedisBase.php ------ redis操作基类
│ ├─pool
│ │ ├─RedisPool.php ------- Redis连接池封装类
│ ├─Redis.php ---------------- swoole一键协程封装
一、封装redis操作类
- RedisBase.php
<?php
/**
* redis操作基类
*/
namespace App\redis_pool\redis;
Class RedisBase{
//连接池
protected $pool;
//Redis连接
protected $redis;
public function __construct($pool)
{
$this->pool = $pool;
}
public function connection()
{
return $this->pool->get();
}
/**
* 从池中或得连接给到Redis属性
*/
public function getRedis()
{
return $this->redis = $this->connection();
}
public function __call($name, $arguments)
{
if (!method_exists($this,$name)){
throw new \RuntimeException("{
$name} Method doesn't exist!");
}
call_user_func("getRedis");
call_user_func_array([$this,$name],$arguments)