Files
zhamao-framework/src/ZM/Store/Redis/ZMRedisPool.php
2021-02-09 17:09:09 +08:00

38 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
}
}
}