get() public method

public get ( $key )
Beispiel #1
0
 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!');
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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
 }
function test3()
{
    $conf = array('cluster' => array('127.0.0.1:7001'));
    $cache = new RedisCache($conf);
    for ($i = 0; $i < 100; $i++) {
        //$cache->set('a' . $i, 'hello' . $i);
        if ($cache->get('a' . $i) == 'hello' . $i) {
            $c = '.';
        } else {
            $c = '*';
        }
        echo $c;
        flush();
    }
    echo "\n";
}
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #6
0
<?php

global $mdb;
$involved = array();
$message = '';
$id = (int) $id;
while ($mdb->count('queueInfo', ['killID' => $id])) {
    sleep(1);
}
$exists = $mdb->exists('killmails', ['killID' => $id]);
if (!$exists) {
    return $app->render('404.html', array('message' => "KillID {$id} does not exist."), 404);
}
$killKey = "CacheKill:{$id}:{$pageview}";
$details = RedisCache::get($killKey);
if ($details == null) {
    // Create the details on this kill
    $killdata = Kills::getKillDetails($id);
    // create the dropdown involved array
    $allinvolved = $killdata['involved'];
    $cnt = 0;
    while ($cnt < 10) {
        if (isset($allinvolved[$cnt])) {
            $involved[] = $allinvolved[$cnt];
            unset($allinvolved[$cnt]);
        }
        ++$cnt;
        continue;
    }
    $topDamage = $finalBlow = null;
    $first = null;
Beispiel #7
0
 /**
  * @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;
 }
Beispiel #8
0
    $url = "/related/{$systemID}/{$relatedTime}/o/{$json}/";
    $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);
}
Beispiel #9
0
 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;
 }
Beispiel #10
0
 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;
 }
Beispiel #11
0
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;
}
Beispiel #12
0
/**
 * 获取微信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;
}
Beispiel #13
0
	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;
	}