Swoole提供了7個內存操作的模塊,在多進程編程中可以幫助開發(fā)者實現一些特殊的需求。
優(yōu)點
Memory下的模塊可以安全的用于異步非阻塞程序中,不存在任何IO消耗
所有模塊均為多進程安全的,無需擔心數據同步問題
Memory相關模塊對象為有限資源,不可大量創(chuàng)建
table
swoole_table一個基于共享內存和鎖實現的超高性能,并發(fā)數據結構。用于解決多進程/多線程數據共享和同步加鎖問題。
<?php
/**
* Created by PhpStorm.
* User: season
* Date: 18-5-8
* Time: 下午3:11
*/
//創(chuàng)建內存表
$table = new swoole_table(1024);
//內存表增加一行
$table->column('id', $table::TYPE_INT, 4);
$table->column('name', $table::TYPE_STRING, 64);
$table->column('age', $table::TYPE_INT, 3);
$table->create();
$table->set('1', ['id' => 1, 'name' => 'season', 'age' => 30]);
//也可以這樣寫
$table['2'] = ['id' => 2, 'name' => 'season2', 'age' => 32];
print_r($table->get('1'));
//可以這樣讀
print_r($table['2']);
//刪除
$table->del('1');
運行結果:

內存表