内存操作模块之:Table
swoole_table一个基于共享内存和锁实现的超高性能,并发数据结构
使用场景:用于解决多进程/多线程数据共享和同步加锁问题
进程结束后内存表会自动释放
// 创建内存表
$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('singwa_imooc', ['id' => 1, 'name'=> 'singwa', 'age' => 30]);
// 另外一种方案
$table['singwa_imooc_2'] = [
'id' => 2,
'name' => 'singwa2',
'age' => 31,
];
$table->decr('singwa_imooc_2', 'age', 2);
print_r($table['singwa_imooc_2']);
echo "delete start:".PHP_EOL;
$table->del('singwa_imooc_2');
print_r($table['singwa_imooc_2']);
本文介绍 Swoole 的 Table 模块,一种基于共享内存和锁机制的高性能并发数据结构,适用于多进程或多线程环境下的数据共享与同步。通过示例展示如何创建内存表、设置列类型及数据操作。
674

被折叠的 条评论
为什么被折叠?



