swoole_exmple/Server/table.php
Wenbin.Wang 1be654dd5f 代码
2021-12-24 16:44:53 +08:00

50 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class table
{
public function doJob()
{
// 创建内存表指定大小为10242的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();