/** * 工厂模式实例化常用缓存类 * * @access public * * @param string $adapter 缓存类型 * @param array $options 参数 * * @return object */ public static function factory($adapter, $options = null) { //参数分析 if (!$adapter) { return false; } $adapter = trim($adapter); $object = false; //分析缓存引擎 switch ($adapter) { case 'Memcache': $object = Cache_Memcache::getInstance($options); break; case 'Redis': $object = Cache_Redis::getInstance($options); break; case 'File': case 'Apc': case 'Xcache': case 'Wincache': case 'Eaccelerator': $object = Doit::singleton('Cache_' . $adapter); break; } return $object; }
public function sentnew($pDid, $pData) { $tMO = new Web_MembersgetuiModel(); $tRow = $tMO->field('devicetoken,cid')->where('did = \'' . $pDid . '\'')->fRow(); if (!count($tRow)) { return false; } $tRedis = Cache_Redis::instance(); $tData = array_merge($tRow, $pData); $tData = serialize($tData); $tRedis->lpush('dakang_msg_new', $tData); }
private function sent() { $tRedis = Cache_Redis::instance(); $tRes = $tRedis->rpop('dakang_getui'); if (empty($tRes)) { return; } $tRow = unserialize($tRes); $tUrl = Yaf_Registry::get("config")->web->url->getui . '/getui?cid=' . $tRow['cid'] . '&title=' . $tRow['title'] . '&content=' . $tRow['content'] . '&devicetoken=' . $tRow['devicetoken'] . '&type=' . $tRow['type'] . '&id=' . $tRow['id']; echo $tUrl; file_get_contents($tUrl); }
public function indexAction() { $tTime = time(); $tMO = new ArticleModel(); $tDatas = $tMO->field('title,id,description')->where('is_tui = 0 and status = 1 and push_time <= ' . $tTime)->fList(); print_R($tDatas); if (!count($tDatas)) { exit; } $tGMO = new GetuiModel(); $tGDatas = $tGMO->field('devicetoken,cid')->fList(); $tRedis = Cache_Redis::instance(); foreach ($tDatas as $tRow) { foreach ($tGDatas as $tR) { $tRes = serialize(array_merge($tRow, $tR, array('type' => 'article', 'content' => ''))); $tRedis->lpush('dakang_getui', $tRes); } $tData = array('is_tui' => 1, 'id' => $tRow['id']); $tMO->update($tData); } exit; }
static function getAddrByCache($pKey, $pCache = 0, $coin) { if (empty($coin)) { return FALSE; } $tRedis =& Cache_Redis::instance(); if ($pCache && ($tAddr = $tRedis->hget($coin . 'addr', $pKey))) { return $tAddr; } if ($pCache && ($tAddr = $tRedis->hget($coin . 'addrnew', $pKey))) { return $tAddr; } if (1 == $pCache) { return false; } $tARC = new Api_Rpc_Client(Yaf_Application::app()->getConfig()->api->rpcurl->{$coin}); $tAddr = $tARC->getnewaddress($pKey); $tRedis->hset($coin . 'addrnew', $pKey, $tAddr); #dumpprivkey $key_priv = $tARC->dumpprivkey($tAddr); file_put_contents('/var/www/ybcoin_log/addrkeys.log', "{$pKey} {$tAddr} {$key_priv} " . date('YmdHi') . " \n", FILE_APPEND); return $tAddr; }
private function sent() { $tRedis = Cache_Redis::instance(); $tRes = $tRedis->rpop('dakang_sms'); if (empty($tRes)) { return; } $tRow = unserialize($tRes); if (!count($tRow)) { return false; } if ($tRow['type'] == 'tx') { $apikey = Yaf_Registry::get("config")->yunpian->sms->apikey; //请用自己的apikey代替 $mobile = $tRow['phone']; //请用自己的手机号代替 $tpl_id = 1185505; //对应默认模板 【#company#】您的验证码是#code# $tpl_value = $tRow['tpl_val']; #print_r($tRow); $tRes = $this->tpl_send_sms($apikey, $tpl_id, $tpl_value, $mobile); #print_r($tRes); } }
public function indexAction() { $tTime = time(); $tH = date('H', $tTime); $tRedis = Cache_Redis::instance(); $tMO = new OrdinarydialysistimeModel(); $tODDMO = new OrdinarydialysisdateModel(); $tUMO = new UserModel(); $tUDMO = new UserdidModel(); $tUAMO = new UserassessmentModel(); $tCMO = new CenterModel(); if ($tH >= 7 && $tH <= 11) { #今日提醒 $tWeek = date('w', $tTime); $tDate = date('Y-m-d', $tTime); $tWhere = ' time_code in (2,3)'; $tDatas = $tMO->field('uid,time_code,time')->where($tWhere . ' and week like \'%' . $tWeek . '%\'')->fList(); foreach ($tDatas as $tRow) { #透析中心信息 $tUARow = $tUAMO->field('medical_id')->where('uid = ' . $tRow['uid'])->fRow(); if (!count($tUARow)) { continue; } $tCRow = $tCMO->field('today_weather,name')->where('id = ' . $tUARow['medical_id'])->fRow(); if (!count($tCRow)) { continue; } $tTitle = '透析提醒'; $tTimecodestr = $tRow['time_code'] == 2 ? '下午' : '晚上'; $tTimecodestr .= $tRow['time']; $tTpl_val = '#timecodestr#=今日' . $tTimecodestr . '&#name#=' . $tCRow['name'] . '&#weather#=今日天气' . $tCRow['today_weather']; $tContent = '您#timecodestr#在#name#透析,请准时参加,祝透析顺利。#weather#'; #用户信息 $tURow = $tUMO->field('phone')->where('id = ' . $tRow['uid'])->fRow(); if (!count($tURow)) { continue; } $tRedis->lpush('dakang_sms', serialize(array('content' => $tContent, 'phone' => $tURow['phone'], 'tpl_val' => $tTpl_val, 'type' => 'tx'))); #设备信息 $tSql = 'select cid,devicetoken from (select did from user_did where uid=' . $tRow['uid'] . ') ud,getui where ud.did = getui.did'; $tUDDatas = $tUDMO->query($tSql); $tTimecodestr = date('m月d日', $tTime) . $tTimecodestr; $tContent = '您' . $tTimecodestr . '在' . $tCRow['name'] . '透析,请准时参加,祝透析顺利。明日天气' . $tCRow['today_weather']; foreach ($tUDDatas as $tR) { $tRes = serialize(array_merge(array('title' => $tTitle, 'content' => $tContent, 'type' => 'tx', 'id' => ''), $tR)); $tRedis->lpush('dakang_getui', $tRes); } $tODDRow = $tODDMO->field('count(0) c')->where('uid = ' . $tRow['uid'] . ' and date = \'' . $tDate . '\'')->fRow(); if (!empty($tODDRow['c'])) { continue; } #添加透析日期 $tData = array('date' => $tDate, 'uid' => $tRow['uid'], 'time_code' => $tRow['time_code'], 'created' => $tTime); $tODDMO->insert($tData); } } elseif ($tH >= 13 && $tH <= 21) { #第二天上午 $tWeek = date('w', $tTime + 86400); $tDate = date('Y-m-d', $tTime + 86400); $tWhere = ' time_code = 1'; $tDatas = $tMO->field('uid,time_code,time')->where($tWhere . ' and week like \'%' . $tWeek . '%\'')->fList(); foreach ($tDatas as $tRow) { #透析中心信息 $tUARow = $tUAMO->field('medical_id')->where('uid = ' . $tRow['uid'])->fRow(); if (!count($tUARow)) { continue; } $tCRow = $tCMO->field('tomorrow_weather,name')->where('id = ' . $tUARow['medical_id'])->fRow(); if (!count($tCRow)) { continue; } $tTitle = '透析提醒'; $tTimecodestr = '上午' . $tRow['time']; $tTpl_val = '#timecodestr#=明日' . $tTimecodestr . '&#name#=' . $tCRow['name'] . '&#weather#=今日天气' . $tCRow['tomorrow_weather']; $tContent = '您#timecodestr#在#name#透析,请准时参加,祝透析顺利。#weather#'; #用户信息 $tURow = $tUMO->field('phone')->where('id = ' . $tRow['uid'])->fRow(); if (!count($tURow)) { continue; } $tRedis->lpush('dakang_sms', serialize(array('content' => $tContent, 'phone' => $tURow['phone'], 'tpl_val' => $tTpl_val, 'type' => 'tx'))); #设备信息 $tSql = 'select cid,devicetoken from (select did from user_did where uid=' . $tRow['uid'] . ') ud,getui where ud.did = getui.did'; $tUDDatas = $tUDMO->query($tSql); $tTimecodestr = date('m月d日', $tTime + 86400) . '上午' . $tRow['time']; $tContent = '您' . $tTimecodestr . '在' . $tCRow['name'] . '透析,请准时参加,祝透析顺利。明日天气' . $tCRow['tomorrow_weather']; foreach ($tUDDatas as $tR) { $tRes = serialize(array_merge(array('title' => $tTitle, 'content' => $tContent, 'type' => 'tx', 'id' => ''), $tR)); $tRedis->lpush('dakang_getui', $tRes); } #添加透析日期 $tODDRow = $tODDMO->field('count(0) c')->where('uid = ' . $tRow['uid'] . ' and date = \'' . $tDate . '\'')->fRow(); if (!empty($tODDRow['c'])) { continue; } $tData = array('date' => $tDate, 'uid' => $tRow['uid'], 'time_code' => $tRow['time_code'], 'created' => $tTime); $tODDMO->insert($tData); } } exit; }
public function incognito_real($pDid, $pMid) { $tRedis = Cache_Redis::instance(); $tNumber = $tRedis->hSet('dakang_incognito_real', $pDid, $pMid); }
private function move() { $tRedis = Cache_Redis::instance(); $tKeys = $tRedis->hKeys('dakang_incognito_real'); if (!count($tKeys)) { return; } $tIBPMO = new I_BloodpressureModel(); $tRBPMO = new R_BloodpressureModel(); $tIFAMO = new I_FoodaddModel(); $tRFAMO = new R_FoodaddModel(); $tIWMO = new I_WeightModel(); $tRWMO = new R_WeightModel(); foreach ($tKeys as $tDid) { $tRWMO->begin(); $tUid = $tRedis->hget('dakang_incognito_real', $tDid); if (empty($tUid)) { continue; } $tRedis->hdel('dakang_incognito_real', $tDid); #血压 $tIBPDatas = $tIBPMO->field('*')->where('did = \'' . $tDid . '\'')->fList(); foreach ($tIBPDatas as $tRow) { $tID = $tRow['id']; unset($tRow['id']); unset($tRow['did']); $tRow['uid'] = $tUid; if (!$tRBPMO->insert($tRow)) { $tRWMO->back(); continue; } $tSql = 'delete from ' . $tIBPMO->table . ' where id = ' . $tID; if (!$tIBPMO->exec($tSql)) { $tRWMO->back(); continue; } } #饮食记录 $tIFADatas = $tIFAMO->field('*')->where('did = \'' . $tDid . '\'')->fList(); foreach ($tIFADatas as $tRow) { $tID = $tRow['id']; unset($tRow['id']); unset($tRow['did']); $tRow['uid'] = $tUid; if (!$tRFAMO->insert($tRow)) { $tRWMO->back(); continue; } $tSql = 'delete from ' . $tIFAMO->table . ' where id = ' . $tID; if (!$tIFAMO->exec($tSql)) { $tRWMO->back(); continue; } } #体重 $tIWDatas = $tIWMO->field('*')->where('did = \'' . $tDid . '\'')->fList(); foreach ($tIWDatas as $tRow) { $tID = $tRow['id']; unset($tRow['id']); unset($tRow['did']); $tRow['uid'] = $tUid; if (!$tRWMO->insert($tRow)) { $tRWMO->back(); continue; } $tSql = 'delete from ' . $tIWMO->table . ' where id = ' . $tID; if (!$tIWMO->exec($tSql)) { $tRWMO->back(); continue; } } $tRWMO->commit(); } }
/** * 通过用户ID得到双重口令 * @param $pUid * @return array */ static function getByUid($pUid) { $tGA = array('secret' => '', 'open' => 0); if ($tHotp = Cache_Redis::instance()->hGet('user_ga', $pUid)) { list($tGA['secret'], $tGA['open']) = explode(',', $tHotp); } return $tGA; }
/** * 获取redis缓存 */ private function _redis() { $ret = 0; $redis = Cache_Redis::get_instance(); if ($redis->enabled()) { $ret = $redis->incr($this->_key, 1); if (!$ret) { $redis->set($this->_key, 1, $this->_interval); $ret = 1; } } return $ret; }
public function indexAction() { $tTime = time(); $tH = date('H', $tTime); $tMO = new BqeschedulingdetailModel(); $tUMO = new UserModel(); $tUDMO = new UserdidModel(); $tUAMO = new UserassessmentModel(); $tCMO = new CenterModel(); $tRedis = Cache_Redis::instance(); echo '<pre>'; if ($tH >= 7 && $tH <= 11) { #今日提醒 $tDatas = $tMO->field('uid,time_code')->where('scheduling_date = \'' . date('Y-m-d', $tTime) . '\' and time_code in(2,3) and uid <> 0')->fList(); foreach ($tDatas as $tRow) { #透析中心信息 $tUARow = $tUAMO->field('medical_id')->where('uid = ' . $tRow['uid'])->fRow(); if (!count($tUARow)) { continue; } $tCRow = $tCMO->field('today_weather,name')->where('id = ' . $tUARow['medical_id'])->fRow(); if (!count($tCRow)) { continue; } $tTitle = '透析提醒'; $tTitle = '透析提醒'; $tTimecodestr = $tRow['time_code'] == 2 ? '下午' : '晚上'; $tTpl_val = '#timecodestr#=今日' . $tTimecodestr . '&#name#=' . $tCRow['name'] . '&#weather#=今日天气' . $tCRow['today_weather']; $tContent = '您#timecodestr#在#name#透析,请准时参加,祝透析顺利。#weather#'; #用户信息 $tURow = $tUMO->field('phone')->where('id = ' . $tRow['uid'])->fRow(); if (!count($tURow)) { continue; } $tRedis->lpush('dakang_sms', serialize(array('content' => $tContent, 'phone' => $tURow['phone'], 'tpl_val' => $tTpl_val, 'type' => 'tx'))); #设备信息 $tSql = 'select cid,devicetoken from (select did from user_did where uid=' . $tRow['uid'] . ') ud,getui where ud.did = getui.did'; $tUDDatas = $tUDMO->query($tSql); $tTimecodestr = date('m月d日', $tTime) . $tTimecodestr; $tContent = '您' . $tTimecodestr . '在' . $tCRow['name'] . '透析,请准时参加,祝透析顺利。明日天气' . $tCRow['today_weather']; foreach ($tUDDatas as $tR) { $tRes = serialize(array_merge(array('title' => $tTitle, 'content' => $tContent, 'type' => 'tx', 'id' => ''), $tR)); $tRedis->lpush('dakang_getui', $tRes); } } } elseif ($tH >= 19 && $tH <= 21) { $tTimeCode = 1; #第二天上午 $tDatas = $tMO->field('uid')->where('scheduling_date = \'' . date('Y-m-d', $tTime + 86400) . '\' and time_code = ' . $tTimeCode)->fList(); foreach ($tDatas as $tRow) { #透析中心信息 $tUARow = $tUAMO->field('medical_id')->where('uid = ' . $tRow['uid'])->fRow(); if (!count($tUARow)) { continue; } $tCRow = $tCMO->field('tomorrow_weather,name')->where('id = ' . $tUARow['medical_id'])->fRow(); if (!count($tCRow)) { continue; } $tTitle = '透析提醒'; $tTimecodestr = '上午'; $tTpl_val = '#timecodestr#=明日' . $tTimecodestr . '&#name#=' . $tCRow['name'] . '&#weather#=明日天气' . $tCRow['tomorrow_weather']; $tContent = '您#timecodestr#在#name#透析,请准时参加,祝透析顺利。#weather#'; #用户信息 $tURow = $tUMO->field('phone')->where('id = ' . $tRow['uid'])->fRow(); if (!count($tURow)) { continue; } $tRedis->lpush('dakang_sms', serialize(array('content' => $tContent, 'phone' => $tURow['phone']))); #设备信息 $tSql = 'select cid,devicetoken from (select did from user_did where uid=' . $tRow['uid'] . ') ud,getui where ud.did = getui.did'; $tUDDatas = $tUDMO->query($tSql); $tTimecodestr = date('m月d日', $tTime + 86400) . '上午' . $tRow['time']; $tContent = '您' . $tTimecodestr . '在' . $tCRow['name'] . '透析,请准时参加,祝透析顺利。明日天气' . $tCRow['tomorrow_weather']; foreach ($tUDDatas as $tR) { $tRes = serialize(array_merge(array('title' => $tTitle, 'content' => $tContent, 'type' => 'tx', 'id' => ''), $tR)); $tRedis->lpush('dakang_getui', $tRes); } } } }
/** * 获取以父ID为KEY的分类 * * @param int $pPid 父ID * @param int $pMeId 输出一个类别 */ static function catdata($pPid = false, $pMeId = 0) { static $datas = array(); if (!$datas) { foreach (Cache_Redis::hget('category') as $v1) { $v1 = json_decode($v1, true); $datas[$v1['pid']][$v1['cid']] = $v1; } } if (false === $pPid) { return $datas; } return $pMeId ? $datas[$pPid][$pMeId] : $datas[$pPid]; }
/** * 单例模式 * * @access public * * @param array $params 数据库连接参数 * * @return object */ public static function getInstance($params = null) { if (!self::$_instance) { self::$_instance = new self($params); } return self::$_instance; }