コード例 #1
0
ファイル: nosql.php プロジェクト: vetermanve/vk_workmart
/**
 * @param $redisId
 *
 * @return Redis|bool
 */
function _storage_nosql_connect($redisId)
{
    static $allConnectionsConfig;
    static $connections;
    lets_use('core_config');
    if (isset($connections[$redisId])) {
        return $connections[$redisId];
    }
    if (!isset($allConnectionsConfig)) {
        $allConnectionsConfig = core_config_get('redis', []);
    }
    if (!isset($allConnectionsConfig[$redisId])) {
        core_error('redis config not found for id:' . serialize($redisId));
        return false;
    }
    $connectionConfig = $allConnectionsConfig[$redisId];
    $connection = new Redis();
    $connected = $connection->connect($connectionConfig['host'], $connectionConfig['port'], $connectionConfig['connect_timeout']);
    if (!$connected) {
        core_error('Cannot connect redis driver');
        return false;
    }
    $connection->setOption(Redis::OPT_READ_TIMEOUT, $connectionConfig['read_timeout']);
    return $connections[$redisId] = $connection;
}
コード例 #2
0
ファイル: db.php プロジェクト: vetermanve/vk_workmart
function _storage_db_get_part($table)
{
    static $cache;
    if (!$cache) {
        $tablesConfig = core_config_get('db_tables', []);
        foreach ($tablesConfig as $dbPart => $partTables) {
            foreach ($partTables as $partTable) {
                $cache[$partTable] = $dbPart;
            }
        }
    }
    if (isset($cache[$table])) {
        return $cache[$table];
    }
    if (isset($cache['*'])) {
        return $cache['*'];
    }
    trigger_error('Db partition fot table: "' . $table . '"' . ' not found', E_USER_WARNING);
}