php Memcache中實(shí)現(xiàn)消息隊(duì)列_第1頁
php Memcache中實(shí)現(xiàn)消息隊(duì)列_第2頁
php Memcache中實(shí)現(xiàn)消息隊(duì)列_第3頁
php Memcache中實(shí)現(xiàn)消息隊(duì)列_第4頁
php Memcache中實(shí)現(xiàn)消息隊(duì)列_第5頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論