/** * 用户资料更新 * @param int $mid * @param array $fields **/ public function updateInfo($mid, $fields = array()) { $update = ""; foreach ($fields as $key => $val) { if (is_null($val)) { continue; } $update .= $key . "='" . $val . "',"; } $update = substr($update, 0, -1); $sql = "UPDATE {$this->memberinfo} SET {$update} WHERE mid={$mid} LIMIT 1"; $flag = Loader_Mysql::dbmaster()->query($sql); if ($flag) { //更新成功 更新缓存 $aUser = Member::factory()->getOneById($mid, false); foreach ($fields as $key => $val) { if (isset($aUser[$key])) { $aUser[$key] = $val; } } //更新缓存 $cacheKey = Core_Keys::getOneById($mid); return Loader_Memcached::minfo($mid)->set($cacheKey, Values::combine(Values::getmb(), $aUser), 3 * 24 * 3600); } return false; }
/** * 用戶完成新手教程更新 * @param $mid * @param $param 要更新的參數 */ public function updateUserParam($mid, $param = array()) { if (!($mid = Helper::uint($mid))) { return false; } $update = ""; if (isset($param['mtaskcount'])) { $update .= ",mtaskcount=mtaskcount+1"; } if ($update) { $update = substr($update, 1); $query = "UPDATE {$this->members} SET {$update} WHERE mid={$mid} LIMIT 1"; Loader_Mysql::dbmaster()->query($query); if (Loader_Mysql::dbmaster()->affectedRows()) { //更新 cache $aUser = $this->getOneById($mid, false); $aUser['mtaskcount'] += 1; $cacheKey = Core_Keys::getOneById($mid); $flag = Loader_Memcached::minfo($mid)->set($cacheKey, Values::combine(Values::getmb(), $aUser), 10 * 24 * 3600); } else { $flag = false; } } return $flag; }
/** *获取游客和独立站点的登录类型的缓存 */ public function loginType($mid, $type, $expire = 300) { $loginTypeKey = Core_Keys::mkLoginType($mid); Loader_Memcached::cache()->set($loginKey, $type, $expire); }
/** * 获取单个用户最新资料 * @param int $mid * @return Array * array( $mid, $exp, $level, $wintime, $losttime, $activetime, $tid, $sid ); */ public function GetRecord($mid) { if (!($mid = Helper::uint($mid))) { return array(); } if (!($aInfo = Loader_Memcached::CserverCache()->get((int) $mid))) { return array(); } $userInfo['mid'] = $mid; $aInfo = explode(',', $aInfo); $keyArr = array_keys($this->KeyArr); foreach ($aInfo as $key => $v) { $userInfo[$keyArr[$key]] = $v; } return (array) $userInfo; }
<?php defined('YUEAI') or exit('Access Denied!'); if ($_GET['debug'] == 1) { ini_set('display_errors', 1); error_reporting(E_ALL); } //ijBTM3pvJ3rIhuen1uTasD7PhitBOGNb_o8949aoPNGEsWjScWTisCa-zEpbok9jKtiGO3ih5FxbIwJhfqz3xw== $cmd = $_GET['cmd']; $mid = $_GET['mid']; switch ($cmd) { case "userinfo": $info = Member::factory()->getOneById($mid); print_R($info); break; case "test": echo "hello world"; break; case "redis": $cachekey = 'sblacktest'; var_dump(Loader_Redis::Redis()->set($cachekey, 1, false, false, 300)); echo Loader_Redis::Redis()->get($cachekey, false, false); print_r(Loader_Redis::Redis()->info()); break; case "memcache": Loader_Memcached::cache()->set('sb', 2, 600); echo Loader_Memcached::cache()->get('sb'); break; default: exit('you are son of bitch'); }