feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
68
addons/shopro/library/Redis.php
普通文件
68
addons/shopro/library/Redis.php
普通文件
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\library;
|
||||
|
||||
use addons\shopro\exception\Exception;
|
||||
|
||||
class Redis
|
||||
{
|
||||
protected $handler = null;
|
||||
|
||||
protected $options = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 6379,
|
||||
'password' => '',
|
||||
'select' => 0,
|
||||
'timeout' => 0,
|
||||
'expire' => 0,
|
||||
'persistent' => false,
|
||||
'prefix' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param array $options 缓存参数
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($options = [])
|
||||
{
|
||||
if (!extension_loaded('redis')) {
|
||||
throw new \BadFunctionCallException('not support: redis');
|
||||
}
|
||||
|
||||
// 获取 redis 配置
|
||||
$config = \think\Config::get('redis');
|
||||
if (empty($config) && empty($options)) {
|
||||
throw new \Exception('redis connection fail: no redis config');
|
||||
}
|
||||
|
||||
if (!empty($config)) {
|
||||
$this->options = array_merge($this->options, $config);
|
||||
}
|
||||
|
||||
if (!empty($options)) {
|
||||
$this->options = array_merge($this->options, $options);
|
||||
}
|
||||
$this->handler = new \Redis();
|
||||
if ($this->options['persistent']) {
|
||||
$this->handler->pconnect($this->options['host'], $this->options['port'], $this->options['timeout'], 'persistent_id_' . $this->options['select']);
|
||||
} else {
|
||||
$this->handler->connect($this->options['host'], $this->options['port'], $this->options['timeout']);
|
||||
}
|
||||
|
||||
if ('' != $this->options['password']) {
|
||||
$this->handler->auth($this->options['password']);
|
||||
}
|
||||
|
||||
if (0 != $this->options['select']) {
|
||||
$this->handler->select($this->options['select']);
|
||||
}
|
||||
|
||||
// 赋值全局,避免多次实例化
|
||||
$GLOBALS['SPREDIS'] = $this->handler;
|
||||
}
|
||||
|
||||
public function getRedis() {
|
||||
return $this->handler;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户