Swoole 記憶體操作(Table)

2022-08-21 07:30:18 字數 1002 閱讀 3568

使用:

//

例項化**,引數 int : 最大行數

$table = new swoole_table(1024);

//設定**字段 引數 (欄位名:string , 字段型別:int、float、string , 長度:int)

$table->column('id',$table::type_int,4);

$table->column('name',$table::type_string,64);

$table->column('price',$table::type_int,11);

//建立**

$table->create();

//新增資料 兩種方式

$table->set('iphonex',['id'=>1,'name'=>'iphonex','price'=>9999]);

$table['xiaomi'] = ['id'=>2,'name'=>"小公尺",'price'=>3339];

foreach ($table

as$key => $value

) //

單獨設定某欄位自增 引數('表名',』欄位名『,』步長『)

$table->incr('iphonex','price',1000);

var_dump($table->get('iphonex'));

//單獨設定欄位自減

$table->decr('xiaomi','price',1000);

var_dump($table->get('xiaomi'));

//刪除某條資料

$table->del('xiaomi');

//判斷資料是否存在

if(!$table->exist('xiaomi'))

swoole 記憶體表優點:

使用場景:

*swoole_table模組目前為實驗性質,不建議在生產環境使用。請使用成熟的方案redis/apc/yac作為資料共享層

SWOOLE 高效能共享記憶體Table

高效能共享記憶體 table 由於 php 語言不支援多執行緒,因此 swoole 使用多程序模式,在多程序模式下存在程序記憶體隔離,在工作程序內修改 global 全域性變數和超全域性變數時,在其他程序是無效的。設定 worker num 1 時,不存在程序隔離,可以使用全域性變數儲存資料 fds...

Swoole學習筆記 記憶體表table 1

一 個人案例 建立記憶體表物件 table new swoole table 1024 在記憶體表中定義三列 table column id swoole table type int,4 table column name swoole table type string,12 table col...

swoole的記憶體管理swoole table

記憶體操作模組之 tableswoole table乙個基於共享記憶體和鎖實現的超高效能,併發資料結構 使用場景 用於解決多程序 多執行緒資料共享和同步加鎖問題 程序結束後記憶體表會自動釋放 建立記憶體表 table newswoole table 1024 記憶體表增加一列 table colum...