下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
本文格式為Word版,下載可任意編輯——phpMemcache中實(shí)現(xiàn)消息隊(duì)列phpMemcache中實(shí)現(xiàn)消息隊(duì)列
對(duì)于一個(gè)很大的消息隊(duì)列,頻繁舉行舉行大數(shù)據(jù)庫的序列化和反序列化,有太花費(fèi)。下面是我用PHP實(shí)現(xiàn)的一個(gè)消息隊(duì)列,只需要在尾部插入一個(gè)數(shù)據(jù),就操作尾部,不用操作整個(gè)消息隊(duì)列舉行讀取,與操作。但是,這個(gè)消息隊(duì)列不是線程安好的,我只是盡量的制止了沖突的`可能性。假設(shè)消息不是分外的密集,譬如幾秒鐘才一個(gè),還是可以考慮這樣使用的。就跟隨我一起去了解下吧,想了解更多相關(guān)信息請(qǐng)持續(xù)關(guān)注我們我!
假設(shè)你要實(shí)現(xiàn)線程安好的,一個(gè)建議是通過文件舉行鎖定,然后舉行操作。下面是代碼:
復(fù)制代碼代碼如下:
classMemcache_Queue
private$memcache;
private$name;
private$prefix;
function__construct$maxSize,$name,$memcache,$prefix=__memcache_queue__
if$memcache==null
thrownewExceptionmemcacheobjectisnull,newtheobjectfirst.;
$this-memcache=$memcache;
$this-name=$name;
$this-prefix=$prefix;
$this-maxSize=$maxSize;
$this-front=0;
$this-real=0;
$this-size=0;
function__get$name
return$this-get$name;
function__set$name,$value
$this-add$name,$value;
return$this;
functionisEmpty
return$this-size==0;
functionisFull
return$this-size==$this-maxSize;
functionenQueue$data
if$this-isFull
thrownewExceptionQueueisFull;
$this-incrementsize;
$this-set$this-real,$data;
$this-setreal,$this-real+1%$this-maxSize;
return$this;
functiondeQueue
if$this-isEmpty
thrownewExceptionQueueisEmpty;
$this-decrementsize;
$this-delete$this-front;
$this-setfront,$this-front+1%$this-maxSize;
return$this;
functiongetTop
return$this-get$this-front;
functiongetAll
return$this-getPage;
functiongetPage$offset=0,$limit=0
if$this-isEmpty||$this-size$offset
returnnull;
$keys[]=$this-getKeyByPos$this-front+$offset%$this-maxSize;
$num=1;
for$pos=$this-front+$offset+1%$this-maxSize;$pos!=$this-real;$pos=$pos+1%$this-maxSize
$keys[]=$this-getKeyByPos$pos;
$num++;
if$limit0$limit==$num
break;
returnarray_values$this-memcache-get$keys;
functionmakeEmpty
$keys=$this-getAllKeys;
foreach$keysas$value
$this-delete$value;
$this-deletereal;
$this-deletefront;
$this-deletesize;
$this-deletemaxSize;
privatefunctiongetAllKeys
if$this-isEmpty
returnarray;
$keys[]=$this-getKeyByPos$this-front;
for$pos=$this-front+1%$this-maxSize;$pos!=$this-real;$pos=$pos+1%$this-maxSize
$keys[]=$this-getKeyByPos$pos;
return$keys;
privatefunctionadd$pos,$data
$this-memcache-add$this-getKeyByPos$pos,$data;
return$this;
privatefunctionincrement$pos
return$this-memcache-increment$this-getKeyByPos$pos;
privatefunctiondecrement$pos
$this-memcache-decrement$this-getKeyByPos$pos;
privatefunctionset$pos,$data
$this-memcache-set$this-getKeyByPos$pos,$data;
return$this;
privatefunctionget$pos
return$this-memcache-get$this-getKeyByPos$pos;
privatefunctionde
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年莆田市公安局面向社會(huì)及退役軍人公開招聘警務(wù)輔助人員148人備考題庫及1套參考答案詳解
- 2025年鈉離子電池電解液五年儲(chǔ)能應(yīng)用分析報(bào)告
- 2025重慶市黔江區(qū)婦幼保健院招聘編外1人備考核心題庫及答案解析
- 梓潼縣2025年下半年公開考核招聘衛(wèi)生專業(yè)技術(shù)人員(26人)筆試重點(diǎn)題庫及答案解析
- 2025陸軍軍醫(yī)大學(xué)西南醫(yī)院護(hù)士長(zhǎng)招聘9人考試核心題庫及答案解析
- 2025隴塬大數(shù)據(jù)服務(wù)(定西)有限公司招聘53人(甘肅)參考考試試題及答案解析
- 2025年兒童益智玩具創(chuàng)新趨勢(shì)與安全標(biāo)準(zhǔn)五年發(fā)展報(bào)告
- 2025福建廈門市集美區(qū)寧寶幼兒園非在編廚房人員招聘1人筆試重點(diǎn)試題及答案解析
- 跨境電商平臺(tái)2025年跨境電商支付:構(gòu)建與便捷交易報(bào)告
- 2025錦州市部分事業(yè)單位赴高校公開招聘2026年應(yīng)屆畢業(yè)生(第二批)考試重點(diǎn)試題及答案解析
- 護(hù)膚銷售技巧培訓(xùn)大綱
- 土地改良合同范本
- 煤礦安全隱患排查及整改措施
- 2025年懷集縣事業(yè)單位聯(lián)考招聘考試真題匯編附答案
- 房開裝潢合同范本
- (新教材)2026年人教版八年級(jí)下冊(cè)數(shù)學(xué) 24.2 數(shù)據(jù)的離散程度 課件
- 急性腎損傷教學(xué)課件
- 死亡病例討論:護(hù)理版
- 股權(quán)退出協(xié)議書模板
- 浙江精誠聯(lián)盟2025-2026學(xué)年高三上學(xué)期12月考試化學(xué)試卷
- GJB1406A-2021產(chǎn)品質(zhì)量保證大綱要求
評(píng)論
0/150
提交評(píng)論