You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class table
|
|
|
|
|
{
|
|
|
|
|
public function doJob()
|
|
|
|
|
{
|
|
|
|
|
// 创建内存表,指定大小为1024(2的N次方值)
|
|
|
|
|
$table = new Swoole\Table(1024);
|
|
|
|
|
|
|
|
|
|
// 设置表的列、列类型还有大小
|
|
|
|
|
$table->column('id', $table::TYPE_INT, 4);
|
|
|
|
|
$table->column('name', $table::TYPE_STRING, 10);
|
|
|
|
|
$table->column('age', $table::TYPE_INT, 4);
|
|
|
|
|
|
|
|
|
|
// 创建表
|
|
|
|
|
$table->create();
|
|
|
|
|
|
|
|
|
|
// 设置方式1
|
|
|
|
|
$table['human1'] = [
|
|
|
|
|
'id' => 1,
|
|
|
|
|
'name' => 'neo',
|
|
|
|
|
'age' => 30
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 设置方式2
|
|
|
|
|
$table->set('human2', [
|
|
|
|
|
'id' => 2,
|
|
|
|
|
'name' => 'jason',
|
|
|
|
|
'age' => 28
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 值自增
|
|
|
|
|
$table->incr('human1', 'age', 1);
|
|
|
|
|
// 值自减
|
|
|
|
|
$table->decr('human2', 'age', 2);
|
|
|
|
|
|
|
|
|
|
var_dump($table['human1']);
|
|
|
|
|
var_dump($table->get('human2'));
|
|
|
|
|
|
|
|
|
|
echo 'deleted.' . PHP_EOL;
|
|
|
|
|
|
|
|
|
|
// 删除值
|
|
|
|
|
$table->del('human2');
|
|
|
|
|
|
|
|
|
|
var_dump($table->exist('human2'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$table = new table();
|
|
|
|
|
$table->doJob();
|