Skip to content

Commit

Permalink
table
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglei5 committed Dec 4, 2014
1 parent bf06489 commit 02d5d26
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion doc/13.swoole_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,57 @@ swoole_table->__construct(int $size)
> swoole_table基于行锁,所以单次set/get/del在多线程/多进程的环境下是安全的
set/get/del是原子操作,用户代码中不需要担心数据加锁和同步的问题

**使用示例**
**样例**
```php
$table = new swoole_table(1024);
```

## column
**功能描述**:给内存表增加一列
**函数原型**
```php
bool swoole_table->column(string $name, int $type, $size);
```

**参数说明**

| 参数 | 说明 |
| -------- | -------- |
| string name | 新增的字段名称 |
| int type | swoole_table支持的3种字段类型,详情见[常量列表](#%E5%B8%B8%E9%87%8F%E5%88%97%E8%A1%A8) |
| int size | 这是根据type的不同占用的字节数 |

**说明**

> swoole_table::TYPE_INT默认为4个字节,可以设置1,2,4,8一共4种长度
swoole_table::TYPE_STRING设置后,set操作不能设置的值不能超过此长度
swoole_table::TYPE_FLOAT会占用8个字节的内存

**样例**
```php
$table->column('id', swoole_table::TYPE_INT, 4);
```

## create
**功能描述**:创建内存表。
**函数原型**
```php
swoole_table->create()
```
**说明**
创建好表的结构后,执行create后创建表。

> swoole_table使用共享内存来保存数据,在创建子进程前,务必要执行swoole_table->create()
swoole_server中使用swoole_table,swoole_table->create() 必须在swoole_server->start()前执行
**样例**
```php
$table = new swoole_table(1024);
$table->column('id', swoole_table::TYPE_INT, 4); //1,2,4,8
$table->column('name', swoole_table::TYPE_STRING, 64);
$table->column('num', swoole_table::TYPE_FLOAT);
$table->create();

$worker = new swoole_process('child1', false, false);
$worker->start();
```

0 comments on commit 02d5d26

Please sign in to comment.