public function onClose($server, $fd) { if ($this->subscribers->del($fd)) { Cli::out($fd . " unsubscribed"); } else { Cli::out($fd . " disconnected"); } }
public function Del($key) { //Log::Debug("Del $key"); return $this->table->del($key); }
<?php $table = new swoole_table(1024); $table->column('name', swoole_table::TYPE_STRING, 64); $table->column('id', swoole_table::TYPE_INT, 4); //1,2,4,8 $table->column('num', swoole_table::TYPE_FLOAT); $table->create(); $table->set('*****@*****.**', array('id' => 145, 'name' => 'rango1', 'num' => 3.1415)); $table->set('*****@*****.**', array('id' => 358, 'name' => "Rango2", 'num' => 3.1415)); $table->set('*****@*****.**', array('id' => 189, 'name' => 'rango3', 'num' => 3.1415)); foreach ($table as $key => $value) { var_dump($key, $value); } echo "======================= Total Elements: {$table->count()} ============================\n"; $table->del('*****@*****.**'); // delete a exist element foreach ($table as $key => $value) { var_dump($key, $value); } echo "======================= Total Elements: {$table->count()} ============================\n"; $ret = $table->del('a invalid key'); // delete a invalid element var_dump($ret); foreach ($table as $key => $value) { var_dump($key, $value); } echo "======================= Total Elements: {$table->count()} ============================\n";
<?php $table = new swoole_table(1000); //table rows size $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, 4); //4,8 $table->create(); exit; //memory size= 72 * (100000 + 20000) //20% conflict $key = '*****@*****.**'; $table->add($key, array('id' => 145, 'name' => 'rango', 'num' => 3.1415)); $value = $table->get($key); $table->set($key, array('id' => 120, 'num' => 1.414)); $table->del($key); $rows = $table->find(array('id' => 10), swoole_table::FIND_GT); $rows = $table->find(array('id' => 10), swoole_table::FIND_LT); $rows = $table->find(array('id' => 10), swoole_table::FIND_EQ); //default $rows = $table->find(array('id' => 10), swoole_table::FIND_NEQ); $rows = $table->find(array('name' => 'ran'), swoole_table::FIND_LEFTLIKE); $rows = $table->find(array('name' => 'go'), swoole_table::FIND_RIGHTLIKE); while ($row = $table->next()) { var_dump($row); }
<?php /** * The script is used for simulating the usage of swoole_table() and guaranting its usability. */ $table = new swoole_table(1024); $table->column('name', swoole_table::TYPE_STRING, 64); $table->column('id', swoole_table::TYPE_INT, 4); //1,2,4,8 $table->column('num', swoole_table::TYPE_FLOAT); $table->create(); while (true) { $i = rand(1, 1000); $if = rand(0, 1); if ($if) { $table->set($i, ['id' => $i, 'name' => $i, 'num' => $i]); } else { $table->del($i); } var_dump('count ' . $table->count()); }