mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-12 11:15:34 +08:00
initial 2.0.0-a4 commit
This commit is contained in:
37
src/ZM/Store/Redis/ZMRedisPool.php
Normal file
37
src/ZM/Store/Redis/ZMRedisPool.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php /** @noinspection PhpComposerExtensionStubsInspection */
|
||||
|
||||
|
||||
namespace ZM\Store\Redis;
|
||||
|
||||
|
||||
use RedisException;
|
||||
use Swoole\Database\RedisConfig;
|
||||
use Swoole\Database\RedisPool;
|
||||
use ZM\Console\Console;
|
||||
|
||||
class ZMRedisPool
|
||||
{
|
||||
/** @var null|RedisPool */
|
||||
public static $pool = null;
|
||||
|
||||
public static function init($config) {
|
||||
self::$pool = new RedisPool((new RedisConfig())
|
||||
->withHost($config['host'])
|
||||
->withPort($config['port'])
|
||||
->withAuth($config['auth'])
|
||||
->withDbIndex($config['db_index'])
|
||||
->withTimeout($config['timeout'] ?? 1)
|
||||
);
|
||||
try {
|
||||
$r = self::$pool->get()->ping('123');
|
||||
if(strpos(strtolower($r), "123") !== false) {
|
||||
Console::debug("成功连接redis连接池!");
|
||||
} else {
|
||||
var_dump($r);
|
||||
}
|
||||
} catch (RedisException $e) {
|
||||
Console::error("Redis init failed! ".$e->getMessage());
|
||||
self::$pool = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user