public function testMultiGet() { $wrappedRedis = $this->getMock(\Redis::class, ['mget']); $wrappedRedis->expects($this->once())->method('mget')->will($this->returnValue(['Object25', false, 'Object1'])); $redisProvider = new RedisCache($wrappedRedis); $this->assertEquals(['cache/25' => 'Object25', 'cache/1' => 'Object1'], $redisProvider->mget([25 => 'cache/25', 10 => 'cache/10', 1 => 'cache/1'])); }
function test4_set1() { $conf = array('cluster' => array('127.0.0.1:7001', '127.0.0.1:7000')); $cache = new RedisCache($conf); $t1 = microtime(1); for ($i = 0; $i < 10000; $i++) { $cache->set('qw' . $i, 'hello' . $i); } $t2 = microtime(1); var_dump($t2 - $t1); echo "\n"; }
/** * Initiates some needed classes. * * @access public * @return void */ public static function init() { if (!self::$initialized) { global $dsSiteKey; self::$siteKey = $dsSiteKey; self::$DB = wfGetDB(DB_MASTER); self::$redis = RedisCache::getClient('cache'); self::$initialized = true; } }
public static function getInstance($name) { if (!self::$config) { self::$config = (array) new \Config\Redis(); } if (!isset(self::$instance[$name])) { RedisCache::config(self::$config, $name); self::$instance[$name] = RedisCache::getInstance($name); } return self::$instance[$name]; }
public function home() { RedisCache::set('key', 'value', 5, 's'); echo RedisCache::get('key'); // $this->mail = Mail::to(['*****@*****.**', '*****@*****.**']) // ->from('huxiuchang <*****@*****.**>') // ->title('TEST') // ->content('<h1>Hello~~</h1>'); // $this->view = View::make('home')->with('article', Article::first()) // ->withTitle('LOMIC :-D') // ->withOk('OK!'); }
public static function getKills($parameters, $buildQuery = true) { global $mdb; $limit = isset($parameters['limit']) ? (int) $parameters['limit'] : 50; if ($limit > 200) { $limit = 200; } if ($limit < 1) { $limit = 1; } $sortDirection = isset($parameters['orderDirection']) ? $parameters['orderDirection'] == 'asc' ? 1 : -1 : -1; if (isset($parameters['startTime'])) { $sortDirection = 'asc'; } $sortKey = isset($parameters['orderBy']) ? $parameters['orderBy'] : 'killID'; $page = isset($parameters['page']) ? $parameters['page'] == 0 ? 0 : $parameters['page'] - 1 : 0; $hashKey = 'MongoFilter::getKills:' . serialize($parameters) . ":{$limit}:{$page}:{$sortKey}:{$sortDirection}:{$buildQuery}"; $result = RedisCache::get($hashKey); if ($result != null) { return $result; } // Build the query parameters $query = $buildQuery ? self::buildQuery($parameters) : $parameters; if ($query === null) { return; } // Start the query $killmails = $mdb->getCollection('killmails'); $cursor = $killmails->find($query, ['_id' => 0, 'killID' => 1])->timeout(-1); // Apply the sort order $cursor->sort([$sortKey => $sortDirection]); // Apply the limit $limit = isset($parameters['limit']) ? (int) $parameters['limit'] : 50; if ($limit > 200) { $limit = 200; } if ($limit < 1) { $limit = 1; } if ($page > 0) { $cursor->skip($page * $limit); } if (!isset($parameters['nolimit'])) { $cursor->limit($limit); } $result = array(); foreach ($cursor as $row) { $result[] = $row; } RedisCache::set($hashKey, $result, 30); return $result; }
public static function get($killID) { $kill = RedisCache::get("Kill{$killID}"); if ($kill != null) { return $kill; } $kill = Db::queryField('select kill_json from zz_killmails where killID = :killID', 'kill_json', array(':killID' => $killID)); if ($kill != '') { RedisCache::set("Kill{$killID}", $kill); return $kill; } return; // No such kill in database }
/** * Initialize the Redis Cache Engine * * Called automatically by the cache frontend * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array()); * * @param array $settings array of setting for the engine * @return boolean true */ public function init($settings = array()) { $this->settings = array_merge(array('engine' => 'Redis', 'prefix' => Inflector::slug(basename(dirname(dirname(APP)))) . '_'), $settings, RedisCache::settings('cache')); parent::init($this->settings); if (!isset($this->redis)) { $this->redis = new Redis(); $this->redis->pconnect($this->settings['hostname'], $this->settings['port']); if (defined('Redis::SERIALIZER_IGBINARY')) { $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); } else { $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); } } return true; }
/** * {@inheritdoc} */ protected function _doDelete($id) { $result = parent::_doDelete($id); if ($result) { if (is_array($id)) { $key = $this->_getNamespacedId($this->_setKey); $this->_redis->pipeline(function ($pipe) use($key, $id) { foreach ($id as $value) { $pipe->srem($key, $value); } }); } else { $this->_redis->srem($this->_getNamespacedId($this->_setKey), $id); } } return $result; }
/** * Acquire a Redis connection. * * @access protected * @param string [Optiona] Server group key. * Example: 'cache' would look up $wgRedisServers['cached'] * Default: Uses the first index of $wgRedisServers. * @param array [Optional] Additional options, will merge and overwrite default options. * - connectTimeout : The timeout for new connections, in seconds. * Optional, default is 1 second. * - persistent : Set this to true to allow connections to persist across * multiple web requests. False by default. * - password : The authentication password, will be sent to Redis in clear text. * Optional, if it is unspecified, no AUTH command will be sent. * - serializer : Set to "php", "igbinary", or "none". Default is "php". * @param boolean [Optional] Force a new connection, useful when forking processes. * @return mixed Object RedisConnRef or false on failure. */ public static function getClient($group = null, $options = [], $newConnection = false) { global $wgRedisServers; if (!extension_loaded('redis')) { throw new MWException(__METHOD__ . " - The PHP Redis extension is not available. Please enable it on the server to use RedisCache."); } if (empty($wgRedisServers) || !is_array($wgRedisServers)) { MWDebug::log(__METHOD__ . " - \$wgRedisServers must be configured for RedisCache to function."); return false; } if (empty($group)) { $group = 0; $server = current($wgRedisServers); } else { $server = $wgRedisServers[$group]; } if ($newConnection === false && array_key_exists($group, self::$servers)) { return self::$servers[$group]; } if (empty($server) || !is_array($server)) { throw new MWException(__METHOD__ . " - An invalid server group key was passed."); } $pool = \RedisConnectionPool::singleton(array_merge($server['options'], $options)); $redis = $pool->getConnection($server['host'] . ":" . $server['port']); //Concatenate these together for MediaWiki weirdness so it can split them later. if ($redis instanceof RedisConnRef) { //Set up any extra options. RedisConnectionPool does not handle the prefix automatically. if (!empty($server['options']['prefix'])) { $redis->setOption(Redis::OPT_PREFIX, $server['options']['prefix']); } try { $pong = $redis->ping(); if ($pong === '+PONG') { self::$servers[$group] = $redis; } else { $redis = false; } } catch (RedisException $e) { //People using HAProxy will find it will lie about a Redis cluster being healthy when the master is down, but the slaves are up. Doing a PING will cause an immediate disconnect. self::$lastError = $e->getMessage(); $redis = false; } } return $redis; }
/** * Main Executor * * @access public * @param string Sub page passed in the URL. * @return void [Outputs to screen] */ public function execute($subpage) { if ($this->wgUser->isAnon()) { $this->output->showErrorPage('globalwatchlist_error', 'error_gwl_logged_out'); return; } $this->redis = RedisCache::getClient('cache'); $this->templateGlobalWatchlist = new TemplateGlobalWatchlist(); $this->output->addModules('ext.globalwatchlist'); $this->setHeaders(); switch ($subpage) { default: case 'globalwatchlist': $this->globalWatchlist(); break; case 'settings': $this->globalWatchlistSettings(); break; } $this->output->addHTML($this->content); }
/** * Gets killmails. * * @param $parameters an array of parameters to fetch mails for * @param $allTime gets all mails from the beginning of time or not * * @return array */ public static function getKills($parameters = array(), $allTime = true, $includeKillDetails = true) { global $mdb; $hashKey = 'Kills::getKills:' . serialize($parameters); $result = RedisCache::get($hashKey); if ($result != null) { return $result; } $kills = MongoFilter::getKills($parameters); if ($includeKillDetails == false) { return $kills; } $details = []; foreach ($kills as $kill) { $killID = (int) $kill['killID']; $killHashKey = "killDetail:{$killID}"; $killmail = RedisCache::get($killHashKey); if ($killmail == null) { $killmail = $mdb->findDoc('killmails', ['killID' => $killID, 'cacheTime' => 3600]); Info::addInfo($killmail); $killmail['victim'] = $killmail['involved'][0]; $killmail['victim']['killID'] = $killID; foreach ($killmail['involved'] as $inv) { if (@$inv['finalBlow'] === true) { $killmail['finalBlow'] = $inv; } } $killmail['finalBlow']['killID'] = $killID; unset($killmail['_id']); RedisCache::set($killHashKey, $killmail, 3600); } $details[$killID] = $killmail; } RedisCache::set($hashKey, $details, 60); return $details; }
/** * In the event of a catastrophic Redis failure this script can be ran to populate all the backed up data on the master database back into Redis. * * @access public * @return void */ public function execute() { $this->DB = wfGetDB(DB_MASTER); $this->redis = RedisCache::getClient('cache'); /******************************/ /* Lists */ /******************************/ $result = $this->DB->select(['gwl_watchlist'], ['count(*) as items'], null, __METHOD__); $total = $result->fetchRow(); for ($i = 0; $i <= $total['items']; $i += 100) { $result = $this->DB->select(['gwl_watchlist'], ['*'], null, __METHOD__, ['OFFSET' => $i, 'LIMIT' => 100]); while ($row = $result->fetchRow()) { if ($row['global_id'] < 1 || empty($row['site_key'])) { continue; } $this->redis->hSet('globalwatchlist:list:' . $row['global_id'], $row['site_key'], $row['list']); } } /******************************/ /* Settings */ /******************************/ $result = $this->DB->select(['gwl_settings'], ['count(*) as items'], null, __METHOD__); $total = $result->fetchRow(); for ($i = 0; $i <= $total['items']; $i += 100) { $result = $this->DB->select(['gwl_settings'], ['*'], null, __METHOD__, ['OFFSET' => $i, 'LIMIT' => 100]); while ($row = $result->fetchRow()) { if ($row['global_id'] < 1 || empty($row['site_keys'])) { continue; } $this->redis->del($this->redisSitesKey); $siteKeys = unserialize($row['site_keys']); array_unshift($siteKeys, 'globalwatchlist:visibleSites:' . $row['global_id']); call_user_func_array([$this->redis, 'sAdd'], $siteKeys); } } }
public function find($collection, $query = [], $sort = [], $limit = null, $includes = []) { global $longQueryMS; $cacheTime = isset($query['cacheTime']) ? $query['cacheTime'] : 0; unset($query['cacheTime']); // reserved zkb field for caching doesn't need to be in queries $serialized = "Mdb::find|{$collection}|" . serialize($query) . '|' . serialize($sort) . "|{$limit}|" . serialize($includes); $cacheKey = $serialized; if ($cacheTime > 0) { $cached = RedisCache::get($cacheKey); if ($cached != null) { return $cached; } } $timer = new Timer(); $collection = $this->getCollection($collection); $cursor = $collection->find($query, $includes); // Set an appropriate timeout for the query if (php_sapi_name() == 'cli') { $cursor->timeout(-1); } else { $cursor->timeout(35000); } // Set the sort and limit... if (sizeof($sort)) { $cursor->sort($sort); } if ($limit != null) { $cursor->limit($limit); } $result = iterator_to_array($cursor); $time = $timer->stop(); if ($time > $longQueryMS) { Log::log("Long query ({$time}ms): {$serialized}"); } if ($cacheTime > 0 && sizeof($result) > 0) { RedisCache::set($cacheKey, $result, $cacheTime); } return $result; }
/** * Constructor * * @access public * @param array Configuration * @return void */ public function __construct() { global $dsSiteKey; $this->siteKey = $dsSiteKey; $this->redis = RedisCache::getClient('cache'); }
/** * 获取微信ticket * * @param string $appId * @param string $appSercet * @param bool $refresh 如果cache中不存在是否刷新cache * @return string */ function getJsApiTicket($appId, $appSecret, $type = 'jsapi', $refresh = true) { $type = in_array($type, array('jsapi', 'wx_card')) ? $type : 'jsapi'; if ('jsapi' == $type) { $cacherId = SuiShiPHPConfig::get('WX_JS_API_TICKET') . $appId; } else { $cacherId = SuiShiPHPConfig::get('WX_CARD_API_TICKET') . $appId; } $cacher = new RedisCache(SuiShiPHPConfig::get('REDIS_HOST_TOKEN'), SuiShiPHPConfig::get('REDIS_PORT_TOKEN')); $ticket = $cacher->get ( $cacherId ); //TODO test //$token = '2FsxZXKoX6NAS9eV28UIZQz3YwoPXvBf2Gjr1O8bNl9nzKBpZub7_1zZ4gsWC1_LdzcwAJ7lW9oWLDghMWXvAn3w3Gcj63pX7ljpHprqCUE'; if (true !== $refresh) { return $ticket; } if (! $ticket) { // 引入微信api if (! class_exists ( "WeiXinClient" )) { include_once dirname ( __FILE__ ) . "/../API/WeiXinApiCore.class.php"; } $token = getToken($appId, $appSecret); $weixnApi = WeiXinApiCore::getClient ( $appId, $appSecret, $token); $ticket = $weixnApi->getJsApiTicket ($type); if ($ticket) { $cacher->set ( $cacherId, $ticket, 6600/*一小时50分钟*/); } } return $ticket; }
<?php App::import('Lib', 'RedisCache.RedisCache'); if (!RedisCache::hasSettings('cache')) { RedisCache::settings('cache', array('hostname' => '127.0.0.1', 'port' => 6379, 'password' => null)); } if (!RedisCache::hasSettings('session')) { RedisCache::settings('session', array('hostname' => '127.0.0.1', 'port' => 6379, 'password' => null)); }
/** * @param string $url * * @return string|null $result */ public static function getData($url, $cacheTime = 3600) { global $ipsAvailable, $baseAddr; $md5 = md5($url); $result = $cacheTime > 0 ? RedisCache::get($md5) : null; if (!$result) { $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_USERAGENT => "zKillboard dataGetter for site: {$baseAddr}", CURLOPT_TIMEOUT => 30, CURLOPT_POST => false, CURLOPT_FORBID_REUSE => false, CURLOPT_ENCODING => '', CURLOPT_URL => $url, CURLOPT_HTTPHEADER => array('Connection: keep-alive', 'Keep-Alive: timeout=10, max=1000'), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true)); if (count($ipsAvailable) > 0) { $ip = $ipsAvailable[time() % count($ipsAvailable)]; curl_setopt($curl, CURLOPT_INTERFACE, $ip); } $result = curl_exec($curl); if ($cacheTime > 0) { RedisCache::set($md5, $result, $cacheTime); } } return $result; }
$app->redirect($url, 302); die; } $systemInfo = $mdb->findDoc('information', ['cacheTime' => 3600, 'type' => 'solarSystemID', 'id' => $systemID]); $systemName = $systemInfo['name']; $regionInfo = $mdb->findDoc('information', ['cacheTime' => 3600, 'type' => 'regionID', 'id' => $systemInfo['regionID']]); $regionName = $regionInfo['name']; $unixTime = strtotime($relatedTime); $time = date('Y-m-d H:i', $unixTime); $exHours = 1; if ((int) $exHours < 1 || (int) $exHours > 12) { $exHours = 1; } $key = md5("br:{$systemID}:{$relatedTime}:{$exHours}:" . json_encode($json_options) . (isset($battleID) ? ":{$battleID}" : "")); $mc = RedisCache::get($key); if ($mc == null) { $parameters = array('solarSystemID' => $systemID, 'relatedTime' => $relatedTime, 'exHours' => $exHours, 'nolimit' => true); $kills = Kills::getKills($parameters); $summary = Related::buildSummary($kills, $json_options); $mc = array('summary' => $summary, 'systemName' => $systemName, 'regionName' => $regionName, 'time' => $time, 'exHours' => $exHours, 'solarSystemID' => $systemID, 'relatedTime' => $relatedTime, 'options' => json_encode($json_options)); if (isset($battleID) && $battleID > 0) { $teamA = $summary['teamA']['totals']; $teamB = $summary['teamB']['totals']; unset($teamA['groupIDs']); unset($teamB['groupIDs']); $mdb->set("battles", ['battleID' => $battleID], ['teamA' => $teamA]); $mdb->set("battles", ['battleID' => $battleID], ['teamB' => $teamB]); } RedisCache::set($key, $mc, 300); } $app->render('related.html', $mc);
function fittedIsk($md5, $items) { $key = $md5 . 'fittedIsk'; $cache = RedisCache::get($key); if ($cache) { return $cache; } $fittedIsk = 0; $flags = array('High Slots', 'Mid Slots', 'Low Slots', 'SubSystems', 'Rigs', 'Drone Bay', 'Fuel Bay'); foreach ($items as $item) { if (isset($item['flagName']) && in_array($item['flagName'], $flags)) { $qty = isset($item['quantityDropped']) ? $item['quantityDropped'] : 0; $qty += isset($item['quantityDestroyed']) ? $item['quantityDestroyed'] : 0; $fittedIsk = $fittedIsk + $item['price'] * $qty; } } RedisCache::set($key, $fittedIsk, 3600); return $fittedIsk; }
public static function init() { self::$redis = new Client(require BASE_PATH . self::CONFIG_FILE); }
public static function getDistinctCount($groupByColumn, $parameters = []) { global $mdb, $debug, $longQueryMS; $hashKey = "distinctCount::{$groupByColumn}:" . serialize($parameters); $result = RedisCache::get($hashKey); if ($result != null) { return $result; } if ($parameters == []) { $type = $groupByColumn == 'solarSystemID' || $groupByColumn == 'regionID' ? "system.{$groupByColumn}" : "involved.{$groupByColumn}"; $result = $mdb->getCollection('oneWeek')->distinct($type); RedisCache::set($hashKey, sizeof($result), 3600); return sizeof($result); } $query = MongoFilter::buildQuery($parameters); if (!$mdb->exists('oneWeek', $query)) { return []; } $andQuery = MongoFilter::buildQuery($parameters, false); if ($groupByColumn == 'solarSystemID' || $groupByColumn == 'regionID') { $keyField = "system.{$groupByColumn}"; } else { $keyField = "involved.{$groupByColumn}"; } $id = $type = null; if ($groupByColumn == 'solarSystemID' || $groupByColumn == 'regionID') { $type = "system.{$groupByColumn}"; } if ($type == null) { $type = "involved.{$groupByColumn}"; } $timer = new Timer(); $pipeline = []; $pipeline[] = ['$match' => $query]; if ($groupByColumn != 'solarSystemID' && $groupByColumn != 'regionID') { $pipeline[] = ['$unwind' => '$involved']; } if ($type != null && $id != null) { $pipeline[] = ['$match' => [$type => $id]]; } $pipeline[] = ['$match' => [$keyField => ['$ne' => null]]]; $pipeline[] = ['$match' => $andQuery]; $pipeline[] = ['$group' => ['_id' => '$' . $type, 'foo' => ['$sum' => 1]]]; $pipeline[] = ['$group' => ['_id' => 'total', 'value' => ['$sum' => 1]]]; if (!$debug) { MongoCursor::$timeout = -1; } $result = $mdb->getCollection('oneWeek')->aggregateCursor($pipeline); $result = iterator_to_array($result); $time = $timer->stop(); if ($time > $longQueryMS) { Log::log("Distinct Long query ({$time}ms): {$hashKey}"); } $retValue = sizeof($result) == 0 ? 0 : $result[0]['value']; RedisCache::set($hashKey, $retValue, 3600); return $retValue; }
public function __construct() { self::$r = new Redis(self::HOST, self::PORT); }
<?php use Redis; include_once __DIR__ . '/redis/RedisCache.class.php'; include_once __DIR__ . '/redis/RedisStorage.class.php'; include_once __DIR__ . '/redis/RedisMultiCache.class.php'; include_once __DIR__ . '/redis/RedisMultiStorage.class.php'; $config = array('nodes' => array(array('master' => "192.168.8.230:27000", 'slave' => "192.168.8.231:27000"), array('master' => "192.168.8.230:27001", 'slave' => "192.168.8.231:27001"), array('master' => "192.168.8.230:27002", 'slave' => "192.168.8.231:27002"), array('master' => "192.168.8.230:27003", 'slave' => "192.168.8.231:27003"), array('master' => "192.168.8.230:27004", 'slave' => "192.168.8.231:27004"), array('master' => "192.168.8.232:27005", 'slave' => "192.168.8.231:27005"), array('master' => "192.168.8.232:27006", 'slave' => "192.168.8.231:27006"), array('master' => "192.168.8.232:27007", 'slave' => "192.168.8.231:27007"), array('master' => "192.168.8.232:27008", 'slave' => "192.168.8.231:27008"), array('master' => "192.168.8.232:27009", 'slave' => "192.168.8.231:27009")), 'db' => 0); RedisStorage::config($config); $config = array('nodes' => array(array('master' => "192.168.8.230:27000", 'slave' => "192.168.8.231:27000"), array('master' => "192.168.8.230:27001", 'slave' => "192.168.8.231:27001"), array('master' => "192.168.8.230:27002", 'slave' => "192.168.8.231:27002"), array('master' => "192.168.8.230:27003", 'slave' => "192.168.8.231:27003"), array('master' => "192.168.8.230:27004", 'slave' => "192.168.8.231:27004"), array('master' => "192.168.8.232:27005", 'slave' => "192.168.8.231:27005"), array('master' => "192.168.8.232:27006", 'slave' => "192.168.8.231:27006"), array('master' => "192.168.8.232:27007", 'slave' => "192.168.8.231:27007"), array('master' => "192.168.8.232:27008", 'slave' => "192.168.8.231:27008"), array('master' => "192.168.8.232:27009", 'slave' => "192.168.8.231:27009")), 'db' => 2); RedisCache::config($config); //***************************以上入口文件配置一次,向王伟同学要ip端口*************************************** //*******************************cache的使用方法************************************* $cache = RedisCache::getInstance(); $cache->set("key", 1111); var_dump($cache->get("key")); $cache->close(); //如果是PHPSERVER,需要手动调用close来关闭连接。FPM的话就不close也行 //*******************************存储的使用方法************************************* $stor = RedisStorage::getInstance(); $stor->set("key", 1111); var_dump($stor->get("key")); $stor->close(); //如果是PHPSERVER,需要手动调用close来关闭连接。FPM的话就不close也行 //*******************************事務的使用方法(只支持單個key)************************************* $stor = RedisStorage::getInstance(); $stor->MULTI(); $stor->incr("key"); $stor->incr("key"); $stor->incr("key"); $stor->EXEC();
$query = ['$and' => [['involved.characterID' => (int) $killdata['victim']['characterID']], ['killID' => ['$gte' => $id - 200]], ['killID' => ['$lt' => $id]], ['vGroupID' => ['$ne' => 29]]]]; $relatedKill = $mdb->findDoc('killmails', $query); if ($relatedKill) { $relatedShip = ['killID' => $relatedKill['killID'], 'shipTypeID' => $relatedKill['involved'][0]['shipTypeID']]; } } else { $query = ['$and' => [['involved.characterID' => (int) @$killdata['victim']['characterID']], ['killID' => ['$lte' => $id + 200]], ['killID' => ['$gt' => $id]], ['vGroupID' => 29]]]; $relatedKill = $mdb->findDoc('killmails', $query); if ($relatedKill) { $relatedShip = ['killID' => $relatedKill['killID'], 'shipTypeID' => $relatedKill['involved'][0]['shipTypeID']]; } } Info::addInfo($relatedShip); $killdata['victim']['related'] = $relatedShip; $details = array('pageview' => $pageview, 'killdata' => $killdata, 'extra' => $extra, 'message' => $message, 'flags' => Info::$effectToSlot, 'topDamage' => $topDamage, 'finalBlow' => $finalBlow, 'url' => $url); RedisCache::set($killKey, $details, 3600); } $app->render('detail.html', $details); function involvedships($array) { $involved = array(); foreach ($array as $inv) { if (isset($involved[@$inv['shipTypeID']]) && isset($inv['shipName'])) { $involved[$inv['shipTypeID']] = array('shipName' => $inv['shipName'], 'shipTypeID' => $inv['shipTypeID'], 'count' => $involved[$inv['shipTypeID']]['count'] + 1); } elseif (isset($inv['shipTypeID']) && isset($inv['shipName'])) { $involved[$inv['shipTypeID']] = array('shipName' => $inv['shipName'], 'shipTypeID' => $inv['shipTypeID'], 'count' => 1); } else { continue; } } usort($involved, 'sortByOrder');
public function getJsApiTicket($type = 'jsapi') { $type = in_array($type, array('jsapi', 'wx_card')) ? $type : 'jsapi'; if ('jsapi' == $type) { $cacherId = SuiShiPHPConfig::get('WX_JS_API_TICKET') . $this->appId; } else { $cacherId = SuiShiPHPConfig::get('WX_CARD_API_TICKET') . $this->appId; } $cacher = new RedisCache(SuiShiPHPConfig::get('REDIS_HOST_TOKEN'), SuiShiPHPConfig::get('REDIS_PORT_TOKEN')); $ticket = $cacher->get ( $cacherId ); if (! $ticket) { $token = $this->_getAccessToken(); if (! $token) { return false; } // 引入微信api if (! class_exists ( "WeiXinClient" )) { include_once dirname ( __FILE__ ) . "/../API/WeiXinApiCore.class.php"; } $weixinApi = WeiXinApiCore::getClient ($this->appId, $this->appSecret, $token); $ticket = $weixinApi->getJsApiTicket($type); if ($ticket) { $cacher->set ($cacherId, $ticket, 7000/*一小时56分钟*/); } } return $ticket; }