redis 應用:resque 的基本使用

redis 應用:resque 的基本使用

在 sinatra 來做儲存程式碼的動作及回應:

redis 應用:resque 的基本使用

這是利用時間的timestamp做key的一部分,

利用curb也就是curl來把程式碼傳到提供服務所在,

再把程式碼存到redis裡。

用 curl 來當client執行看所要花的時間狀況為:

redis 應用:resque 的基本使用

把要背景工作的動作寫入:

redis 應用:resque 的基本使用

要把需要的gem包進來,

不然程式不曉得怎麼做這些動作。

redis 應用:resque 的基本使用

執行前沒有任何worker

redis 應用:resque 的基本使用

執行:

redis 應用:resque 的基本使用

顯示出有個worker正在等待工作

redis 應用:resque 的基本使用

並在 sinatra 上加入以下代碼:

redis 應用:resque 的基本使用

就是要定義好 ColorCodes 的class,

把原來要用curl傳到別的網站的動作及回應,

統統都寫到給 resqueue 來處理,

然後用 Resque.enqueue 把 class 及所需的參數填入,

即可把工作傳到 resqueue 裡,

resqueue 也需要把這 class 的定義,

在執行 rake resqueue:work 也讀入。

用curl執行的結果為:

redis 應用:resque 的基本使用

與前面所花的時間少了些,

因為測試的代碼很簡短,

感覺差別不大,

但貼了較多的代碼,

就比較會有感了。

redis 應用:resque 的基本使用

顯示已工作過的記錄。


分享到:


相關文章: