<?php lets_sure_loaded('storage_lock'); function storage_lock_get($lockId, $expire = 60, $value = 1) { lets_use('storage_nosql', 'core_config'); return storage_nosql_setnx(CORE_CONFIG_REDIS_MAIN, 'cLock:' . $lockId, $value, $expire); } function storage_lock_release($lockId) { lets_use('storage_nosql', 'core_config'); return storage_nosql_set(CORE_CONFIG_REDIS_MAIN, 'cLock:' . $lockId, null); }
<?php lets_sure_loaded('web_controller_order'); function web_controller_order_precall() { lets_use('user_self'); web_render_add_data('is_auth', user_self_id()); } function web_controller_order_create() { lets_use('user_self'); $authorId = user_self_id(); if (!$authorId) { web_router_redirect('/auth/auth'); return; } if (web_router_get_method() === 'POST') { $cost = web_router_get_param('cost'); if (!$cost) { web_router_render_page('order', 'create', ['msg' => 'Цена должна быть задана', 'error' => 'cost']); return; } $title = web_router_get_param('title'); if (!$title) { web_router_render_page('order', 'create', ['msg' => 'Название должно быть задано', 'error' => 'title']); return; } $desc = web_router_get_param('desc'); if (!$desc) { web_router_render_page('order', 'create', ['msg' => 'Описание должно быть задано', 'error' => 'desc']); return;
<?php lets_sure_loaded('billing_locks'); global $_billing_locks_by_transaction; function billing_locks_lock_transaction($transactionId, $accountsIds) { global $_billing_locks_by_transaction; if (isset($_billing_locks_by_transaction[$transactionId])) { core_error('trying to re-lock non-empty transaction'); return false; } $_billing_locks_by_transaction[$transactionId] = []; foreach ($accountsIds as $accountId) { $lock = _billing_locks_lock($transactionId, $accountId); if (!$lock) { core_error('cant get lock on account:' . $accountId, __FUNCTION__); billing_locks_unlock_transaction($transactionId); return false; } $_billing_locks_by_transaction[$transactionId][] = $accountId; } return true; } function billing_locks_unlock_transaction($transactionId) { global $_billing_locks_by_transaction; foreach ($_billing_locks_by_transaction[$transactionId] as $accountId) { _billing_locks_unlock($accountId); } unset($_billing_locks_by_transaction[$transactionId]); }
<?php lets_sure_loaded('web_response'); const _WEB_RESPONSE_BODY = 'body'; const _WEB_RESPONSE_CODE = 'code'; const _WEB_RESPONSE_CONTENT_TYPE = 'content_type'; const _WEB_RESPONSE_HEADERS = 'headers'; global $_web_response_content_proto; global $_web_response_content; global $_web_response_lock; global $_web_response_cookie; $_web_response_content_proto = [_WEB_RESPONSE_CODE => 200, _WEB_RESPONSE_CONTENT_TYPE => '', _WEB_RESPONSE_HEADERS => [], _WEB_RESPONSE_BODY => '']; $_web_response_content = $_web_response_content_proto; $_web_response_cookie = []; $_web_response_lock = false; function web_response_flush() { global $_web_response_lock; global $_web_response_content; global $_web_response_cookie; // check response already sent if ($_web_response_lock) { core_error('trying to flush on locked response'); return; } // lock response, to prevent second sending $_web_response_lock = true; // set http code =) http_response_code($_web_response_content[_WEB_RESPONSE_CODE]); // first of all send content type if set if ($_web_response_content[_WEB_RESPONSE_CONTENT_TYPE]) {
<?php lets_sure_loaded('billing_transaction'); const BILLING_TRANSACTION_DB_TABLE = 'transactions'; const BILLING_TRANSACTION_FIELD_ID = 'id'; const BILLING_TRANSACTION_FIELD_ACC_FROM = 'acc_from'; const BILLING_TRANSACTION_FIELD_ACC_TO = 'acc_to'; const BILLING_TRANSACTION_FIELD_AMOUNT = 'amount'; const BILLING_TRANSACTION_FIELD_TYPE = 'type'; const BILLING_TRANSACTION_FIELD_RELATED_ID = 'related_id'; const BILLING_TRANSACTION_FIELD_STARTED = 'started'; const BILLING_TRANSACTION_FIELD_STATUS = 'status'; const BILLING_TRANSACTION_STATUS_STARTED = 1; const BILLING_TRANSACTION_STATUS_SUCCESS = 2; const BILLING_TRANSACTION_STATUS_ERROR = 3; /* [Блокировка средств] [100] [в счет] [залога заказа] [Нужно посторить дом] [Возврат сресств] [из] [залога заказа] [Нужно посторить дом] [Уплата] [в счет] [процентов по сделке] [Нужно посторить дом] [Уплата] [в счет] [работ по ] [Нужно посторить дом] [Ввод средств] [из] [источника] [Благотворительный фонд] */ const BILLING_TRANSACTION_TYPE_LOCK = 1; const BILLING_TRANSACTION_TYPE_UNLOCK = 2; const BILLING_TRANSACTION_TYPE_PAY = 3; const BILLING_TRANSACTION_TYPE_REFILL = 4; function billing_transaction_register($accountFrom, $accountTo, $sum, $type = 0, $relatedId = 0) { lets_use('storage_db'); $transactionId = storage_db_insert_row(BILLING_TRANSACTION_DB_TABLE, [BILLING_TRANSACTION_FIELD_ACC_FROM => $accountFrom, BILLING_TRANSACTION_FIELD_ACC_TO => $accountTo, BILLING_TRANSACTION_FIELD_AMOUNT => $sum, BILLING_TRANSACTION_FIELD_TYPE => $type, BILLING_TRANSACTION_FIELD_RELATED_ID => $relatedId, BILLING_TRANSACTION_FIELD_STARTED => time(), BILLING_TRANSACTION_FIELD_STATUS => BILLING_TRANSACTION_STATUS_STARTED]); return $transactionId; } function billing_transaction_success($transactionId)
<?php lets_sure_loaded('billing_balance'); const BILLING_BALANCE_DB_TABLE = 'balance'; const BILLING_BALANCE_FIELD_ACCOUNT_ID = 'acc_id'; const BILLING_BALANCE_FIELD_AMOUNT = 'amount'; function billing_balance_check_sum_available($accountFrom, $sum) { $amount = billing_balance_get_account_amount($accountFrom); return $amount >= $sum; } function billing_balance_get_account_amount($accountId) { lets_use('storage_db'); $amount = storage_db_get_value(BILLING_BALANCE_DB_TABLE, BILLING_BALANCE_FIELD_AMOUNT, [[BILLING_BALANCE_FIELD_ACCOUNT_ID, $accountId]]); return $amount ? _billing_balance_unpack_money($amount) : 0; } function billing_balance_get_accounts($accIds) { lets_use('storage_db'); return storage_db_get_rows(BILLING_BALANCE_DB_TABLE, '*', [[BILLING_BALANCE_FIELD_ACCOUNT_ID, $accIds]], [], BILLING_BALANCE_FIELD_ACCOUNT_ID); } function billing_balance_set_account_amount($accountId, $amount) { lets_use('storage_db'); $bind = [BILLING_BALANCE_FIELD_ACCOUNT_ID => $accountId, BILLING_BALANCE_FIELD_AMOUNT => _billing_balance_pack_money($amount)]; $res = storage_db_set(BILLING_BALANCE_DB_TABLE, $bind); if (!$res) { core_error('cant set money amount: ' . json_encode($bind)); return false; }
<?php lets_sure_loaded('web_controller_billing'); function web_controller_billing_precall() { lets_use('user_self'); $userId = user_self_id(); if (!$userId) { web_router_redirect('/auth/auth'); return false; } web_render_add_data('is_auth', $userId); } function web_controller_billing_add() { lets_use('billing_balance', 'billing_account', 'billing_refill'); $fondAccount = billing_account_get_income_account(BILLING_REFILL_SOURCE_FOND_INCOMING_ID); $fondMoney = billing_balance_get_account_amount($fondAccount); web_router_render_page('billing', 'add', ['fond_money' => number_format($fondMoney, 2, '.', ' ')]); } function web_controller_billing_refill() { lets_use('web_router', 'billing_balance', 'billing_account', 'billing_transaction', 'billing_locks', 'user_self'); $incomingSource = 1; // благотоврительный фонд $sum = (double) web_router_get_param('sum'); $sum = round($sum, 2); $accountFrom = billing_account_get_income_account($incomingSource); $accountTo = billing_account_get_user_main_account(user_self_id()); $trId = billing_transaction_register($accountFrom, $accountTo, $sum); if (!$trId) {
<?php lets_sure_loaded('web_router'); lets_use('web_render', 'web_response'); global $_web_router_request_data; $_web_router_request_data = []; function web_router_route($uri, $get, $post) { global $_web_router_request_data; $_web_router_request_data = (array) $get + (array) $post; $uri = strpos($uri, '?') ? strstr($uri, '?', true) : $uri; $pathInfo = explode('/', trim($uri, '/')); $controllerPart = !empty($pathInfo[0]) ? $pathInfo[0] : 'index'; $actionPart = !empty($pathInfo[1]) ? $pathInfo[1] : 'index'; $controller = str_replace(['_', '/', ' '], '', $controllerPart); $action = str_replace(['_', '/', ' '], '', $actionPart); web_router_call($controller, $action, $uri); } function web_router_call($controller, $action, $uri) { $module = 'web_controller_' . $controller; lets_use($module); // pre dispatch $function = $module . '_precall'; if (function_exists($function)) { try { $function(); } catch (Exception $e) { web_router_error($e->getMessage()); // @todo show error only in debug return;
<?php lets_sure_loaded('user_register'); function user_register_new_user($name, $email, $pass) { lets_use('storage_db'); storage_db_transaction_begin('users'); $userId = storage_db_insert_row('users', ['name' => $name, 'email' => $email]); if (!$userId) { storage_db_transaction_rollback('users'); core_error('cannot save user data to db table'); return false; } lets_use('user_session'); $token = user_session_create_token($userId, $pass); if (!$token) { storage_db_transaction_rollback('users'); core_error('cannot save user token'); return false; } storage_db_transaction_commit('users'); return $userId; } function user_register_get_user_id_by_email($email) { lets_use('storage_db'); $authUserId = storage_db_get_value('users', 'id', [['email', $email]]); return $authUserId; }
<?php lets_sure_loaded('web_render'); lets_use('core'); global $_web_render_global_params; global $_web_render_scope_params; $_web_render_global_params = []; $_web_render_scope_params = []; /** * @param $key * @param string $default * * @return string|array */ function _v($key, $default = '') { global $_web_render_global_params; global $_web_render_scope_params; if (array_key_exists($key, $_web_render_scope_params)) { return $_web_render_scope_params[$key]; } if (array_key_exists($key, $_web_render_global_params)) { return $_web_render_global_params[$key]; } return $default; } function _e($string) { return nl2br(htmlspecialchars(strip_tags($string, '<br><br/><br />'))); } function web_render_page_content($module, $template, $data = [], $layout = 'main')
<?php lets_sure_loaded('core'); global $_core_internal_log; global $_core_start_time; $_core_internal_log = []; function core_init($appRole) { global $_core_start_time; $_core_start_time = microtime(1); lets_use('core_config'); core_config_load(); } function core_error($data, $function = '') { core_log('Error! ' . $data . ' in @' . $function); } function core_log($sting, $function = '') { global $_core_internal_log; $_core_internal_log[] = ($function ? '[' . $function . '] ' : '') . trim($sting); } function core_get_log() { global $_core_internal_log; return $_core_internal_log; } function core_log_work_time() { global $_core_start_time; core_log('WORK TIME ' . round(microtime(1) - $_core_start_time, 3), __FUNCTION__);
<?php lets_sure_loaded('storage_db'); lets_use('core_config'); global $_storage_db_started_transactions; $_storage_db_started_transactions = []; /** * @param $dbPart * * @return mysqli|bool */ function _storage_db_get_connection($dbPart) { static $config; static $connections; if (isset($connections[$dbPart])) { return $connections[$dbPart]; } if (!isset($config)) { $config = core_config_get('db', []); } if (!isset($config[$dbPart])) { core_dump($config); trigger_error($dbPart . ' db connection config not found'); return false; } $partConfig = $config[$dbPart]; $mysqli = mysqli_connect($partConfig['host'], $partConfig['user'], $partConfig['pass'], isset($partConfig['db_name']) ? $partConfig['db_name'] : $dbPart); if (!$mysqli) { trigger_error('Cannot establish connection to db ' . $dbPart . ' with given config. Error: ' . mysqli_connect_error() . '; code: ' . mysqli_connect_errno(), E_USER_ERROR); return false;
<?php lets_sure_loaded('billing_description'); function billing_description_transaction_types() { return [0 => 'Перевод', BILLING_TRANSACTION_TYPE_LOCK => 'Блокировка средств', BILLING_TRANSACTION_TYPE_UNLOCK => 'Возврат сресств', BILLING_TRANSACTION_TYPE_PAY => 'Уплата', BILLING_TRANSACTION_TYPE_REFILL => 'Пополнение']; } function billing_description_account_owner_names($accData) { lets_use('billing_account'); if (!$accData) { return []; } $users = $sources = $result = []; foreach ($accData as &$accInfo) { $id = $accInfo[BILLING_ACCOUNT_FIELD_ID]; $ownerId = $accInfo[BILLING_ACCOUNT_FIELD_OWNER_ID]; switch ($accInfo[BILLING_ACCOUNT_FIELD_TYPE]) { case BILLING_ACCOUNT_TYPE_USER_MAIN: case BILLING_ACCOUNT_TYPE_USER_LOCKED: $users[$id] = $ownerId; break; case BILLING_ACCOUNT_TYPE_INCOMING: $sources[$id] = $ownerId; break; case BILLING_ACCOUNT_TYPE_SYSTEM: default: $result[$id] = ''; break; } }
<?php lets_sure_loaded('web_controller_user'); function web_controller_user_precall() { lets_use('user_self'); web_render_add_data('is_auth', user_self_id()); } function web_controller_user_index() { web_router_render_page('index', 'index'); } function web_controller_user_profile() { lets_use('user_self', 'billing_log'); $balance = user_self_balance(); $transactions = billing_log_get_user_transactions(user_self_id()); web_router_render_page('user', 'profile', ['balance' => $balance, 'transactions' => $transactions]); } function web_controller_user_orders() { web_router_render_page('index', 'index'); }
<?php lets_sure_loaded('billing_account'); const BILLING_ACCOUNT_TYPE_USER_MAIN = 1; const BILLING_ACCOUNT_TYPE_USER_LOCKED = 2; const BILLING_ACCOUNT_TYPE_SYSTEM = 3; const BILLING_ACCOUNT_TYPE_INCOMING = 4; const BILLING_ACCOUNT_DB_TABLE = 'accounts'; const BILLING_ACCOUNT_FIELD_ID = 'id'; const BILLING_ACCOUNT_FIELD_OWNER_ID = 'owner_id'; const BILLING_ACCOUNT_FIELD_TYPE = 'type'; const BILLING_ACCOUNT_FIELD_CREATED = 'created'; function billing_account_get_account($ownerId, $type, $autoCreate) { lets_use('storage_db'); $accountId = storage_db_get_value(BILLING_ACCOUNT_DB_TABLE, BILLING_ACCOUNT_FIELD_ID, [[BILLING_ACCOUNT_FIELD_OWNER_ID, $ownerId], [BILLING_ACCOUNT_FIELD_TYPE, $type]], ['LIMIT' => 1]); if (storage_db_get_last_error(BILLING_ACCOUNT_DB_TABLE)) { core_error('cant fetch account ' . json_encode(func_get_args())); return false; } // create account if (!$accountId && $autoCreate) { $bind = [BILLING_ACCOUNT_FIELD_OWNER_ID => $ownerId, BILLING_ACCOUNT_FIELD_TYPE => $type, BILLING_ACCOUNT_FIELD_CREATED => time()]; $accountId = storage_db_insert_row(BILLING_ACCOUNT_DB_TABLE, $bind); if (!$accountId) { core_error('cant create an account ' . json_encode(func_get_args())); return false; } } return $accountId; }
<?php lets_sure_loaded('user_self'); function user_self_id() { static $id; if (!$id) { lets_use('user_session'); $id = user_session_get_current_user(); } return $id; } function user_self_balance() { lets_use('billing_balance', 'billing_account'); $userId = user_self_id(); core_log('user_id: ' . $userId, __FUNCTION__); if (!$userId) { return 0; } $account = billing_account_get_user_main_account($userId); return billing_balance_get_account_amount($account); }
<?php lets_sure_loaded('core_config'); const CORE_CONFIG_REDIS_MAIN = 'main'; global $_core_config_data; function core_config_load() { global $_core_config_data; if (!$_core_config_data) { $_core_config_data = ['db' => ['db_part1' => ['host' => '127.0.0.1', 'port' => '3606', 'user' => 'lets_db', 'pass' => 'K&25^Ldf^&A9((&sd%#', 'db_name' => 'lets_db_1'], 'db_part2' => ['host' => '127.0.0.1', 'port' => '3606', 'user' => 'lets_db', 'pass' => 'K&25^Ldf^&A9((&sd%#', 'db_name' => 'lets_db_2']], 'redis' => [CORE_CONFIG_REDIS_MAIN => ['host' => '127.0.0.1', 'port' => '6379', 'connect_timeout' => 1, 'read_timeout' => 3]], 'db_tables' => ['db_part1' => ['*', 'orders', 'sessions'], 'db_part2' => ['users', 'balance', 'transactions', 'accounts']]]; } return $_core_config_data; } function core_config_get($key, $default = null) { global $_core_config_data; return isset($_core_config_data[$key]) ? $_core_config_data[$key] : $default; }
<?php /* Модуль пополнения баланса */ lets_sure_loaded('billing_refill'); const BILLING_REFILL_SOURCE_FOND_INCOMING_ID = 1;
<?php lets_sure_loaded('order_storage'); const ORDER_STORAGE_DB_TABLE = 'orders'; const ORDER_STORAGE_ORDER_STATUS_CREATING = 1; const ORDER_STORAGE_ORDER_STATUS_OK = 2; const ORDER_STORAGE_ORDER_STATUS_IN_BILLING = 3; const ORDER_STORAGE_ORDER_STATUS_CLOSED = 4; global $_order_storage_error; function order_storage_get_error() { global $_order_storage_error; return $_order_storage_error; } function order_storage_set_error($error) { global $_order_storage_error; return $_order_storage_error = $error; } function order_storage_create_order($title, $desc, $author, $cost) { lets_use('storage_db'); $orderId = storage_db_insert_row(ORDER_STORAGE_DB_TABLE, ['title' => $title, 'description' => $desc, 'author_id' => $author, 'cost' => $cost, 'created_at' => time(), 'status' => ORDER_STORAGE_ORDER_STATUS_CREATING]); return $orderId; } function order_storage_change_order_status($orderId, $status) { lets_use('storage_db'); $result = storage_db_set(ORDER_STORAGE_DB_TABLE, ['id' => $orderId, 'status' => $status]); return $result; }
<?php lets_sure_loaded('billing_log'); function billing_log_get_user_transactions($userId) { lets_use('billing_account', 'billing_transaction', 'billing_description'); $userMain = billing_account_get_account($userId, BILLING_ACCOUNT_TYPE_USER_MAIN, false); $acc[] = $userMain; $acc[] = billing_account_get_account($userId, BILLING_ACCOUNT_TYPE_USER_LOCKED, false); $acc = array_filter($acc); if (!$acc) { return []; } $tr = billing_transaction_get_accounts_transactions($acc); $types = billing_description_transaction_types(); $accIds = array_unique(array_merge(array_column($tr, BILLING_TRANSACTION_FIELD_ACC_FROM), array_column($tr, BILLING_TRANSACTION_FIELD_ACC_TO))); $accData = billing_account_get_accounts($accIds); $ownersNames = billing_description_account_owner_names($accData); foreach ($tr as &$transaction) { $transaction['str_type'] = isset($types[$transaction[BILLING_TRANSACTION_FIELD_TYPE]]) ? $types[$transaction[BILLING_TRANSACTION_FIELD_TYPE]] : $types[0]; $transaction['target_action'] = $transaction[BILLING_TRANSACTION_FIELD_ACC_FROM] == $userId ? 'в счет' : 'из'; $transaction['prefix'] = $transaction[BILLING_TRANSACTION_FIELD_TYPE] == BILLING_TRANSACTION_TYPE_REFILL ? 'источника' : ''; if ($transaction[BILLING_TRANSACTION_FIELD_ACC_FROM] == $userMain) { $transaction['target_owner'] = $ownersNames[$transaction[BILLING_TRANSACTION_FIELD_ACC_TO]]; } else { $transaction['target_owner'] = $ownersNames[$transaction[BILLING_TRANSACTION_FIELD_ACC_FROM]]; } $transaction['success'] = $transaction['status'] == BILLING_TRANSACTION_STATUS_SUCCESS; } return $tr; }
<?php lets_sure_loaded('user_session'); /* redis */ const USER_SESSION_REDIS_KEY_PREFIX = 'session'; const USER_SESSION_REDIS_MISSING_RECORD = '-1'; /* session table */ const USER_SESSION_DB_TABLE = 'sessions'; /* session secrets */ const USER_SESSION_TOKEN_SECRET = 'Bo)(Hc9an5,234yTXTdrf78IF*(^FV*A%#@UK3N>ZAas4(BV*(N@<JBV*A^%WgFhbc)*6KIVXt#.12=bcLKAksgfd;'; const USER_SESSION_SECRET_GEN = 'ABBVHJxnc^aH>KJ#$fjcb^A$IGbfvyu6a4JKBV76(*&A3br4tll"(VY&T*^YG#MKVPNY(T*&A4 saas'; /* cookie fields */ const USER_SESSION_COOKIE_UID = 'uid'; const USER_SESSION_COOKIE_TOKEN = 'token'; function user_session_init() { $userId = isset($_COOKIE[USER_SESSION_COOKIE_UID]) ? (int) $_COOKIE[USER_SESSION_COOKIE_UID] : null; $authToken = isset($_COOKIE[USER_SESSION_COOKIE_TOKEN]) ? $_COOKIE[USER_SESSION_COOKIE_TOKEN] : null; if (!$userId || !$authToken) { return false; } return user_session_check_token($userId, $authToken); } function user_session_get_current_user() { return user_session_init(); } function user_session_check_token($userId, $authToken) { $secret = user_session_get_secret($userId); $token = user_session_build_token($userId, $secret);
<?php lets_sure_loaded('core_shutdown'); global $_core_shutdown_callbacks; global $_core_shutdown_registered; $_core_shutdown_callbacks = []; function core_shutdown_add_check($name, $callable, $replace = true) { static $registered; global $_core_shutdown_callbacks; if (isset($_core_shutdown_callbacks[$name]) && !$replace) { return; } if (!$registered) { register_shutdown_function('core_shutdown_process_checks'); } if (!is_callable($callable)) { core_error('trying to add not callable shutdown callback with name ' . $name); return; } $_core_shutdown_callbacks[$name] = $callable; } function core_shutdown_remove_check($name) { global $_core_shutdown_callbacks; unset($_core_shutdown_callbacks[$name]); } function core_shutdown_process_checks() { global $_core_shutdown_callbacks; if (empty($_core_shutdown_callbacks)) {
<?php lets_sure_loaded('web_controller_index'); function web_controller_index_precall() { lets_use('user_self'); web_render_add_data('is_auth', user_self_id()); } function web_controller_index_index() { lets_use('user_self'); if (user_self_id()) { web_router_call('order', 'list', ''); return; } web_router_render_page('index', 'index'); }
<?php lets_sure_loaded('web_controller_auth'); lets_use('web_render', 'web_router'); const _AUTH_HASH_SECRET = '^7sc9v6aj%%6a99s0!#d,'; const _AUTH_SALT_SECRET = 'AS@)Nsy8#,a!Rsdf^$'; function web_controller_auth_auth() { $email = web_router_get_param('email'); $pass = web_router_get_param('pass'); if (web_router_get_method() === 'POST') { lets_use('user_register'); $userId = user_register_get_user_id_by_email($email); if ($userId) { lets_use('user_session'); core_log('user found: ' . $userId); $realSecret = user_session_get_secret($userId); $checkSecret = user_session_build_secret($pass); if ($realSecret === $checkSecret) { $token = user_session_build_token($userId, $checkSecret); user_session_write_session_cookie($userId, $token, 86400 * 30); web_response_redirect('/'); return; } } web_router_render_page('auth', 'auth', ['msg' => 'Для данного адреса почты и пароля не найдено ни одного пользователя.']); return; } web_router_render_page('auth', 'auth'); } function web_controller_auth_logout()
<?php lets_sure_loaded('storage_nosql'); /** * @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']);