生活随笔
收集整理的這篇文章主要介紹了
swoole 内存Memory
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.table?
https://wiki.swoole.com/wiki/page/256.html
<?php
/**
* Created by PhpStorm.
* User: whitneywang
* Date: 2018/6/4
* Time: 15:43
*/
//創建內存表
$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, 4);
$table->create();
$table->set('wawa_detail', ['id' => 1, 'name' => 'name', 'age' => 6]);
print_r($table->get('wawa_detail'));
場景:多進程序之間共享數據
//創建內存表
$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, 4);
$table->create();
$table->set('wawa_detail', ['id' => 1, 'name' => 'name', 'age' => 6]);
print_r($table->get('wawa_detail')); //輸出的是數據
//set get另外一種方式
$table['wawa_details'] = [
'id' => 1,
'name' => 'name',
'age' => 5
];
print_r($table['wawa_details']); //輸出的是對象
//對里面某個參數進行加數字操作,這時AGE應該是8, 原子自加操作。
$table->incr('wawa_details', 'age', 3);
print_r($table['wawa_details']); //輸出的是對象
//原子自減操作。
$table->decr('wawa_details', 'age', 2);
print_r($table['wawa_details']); //輸出的是對象
//刪除
echo 'del start:'.PHP_EOL;
$table->del('wawa_details');
print_r($table['wawa_details']);
//等等,可見官方文檔
總結
以上是生活随笔為你收集整理的swoole 内存Memory的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。