diff --git a/examples/servers/redis.php b/examples/servers/redis.php index 0593789..efa40e0 100755 --- a/examples/servers/redis.php +++ b/examples/servers/redis.php @@ -21,21 +21,24 @@ */ use Swoole\Redis\Server; +use Swoole\Table; -$server = new Server('0.0.0.0', 6379); +// We use a Swoole table as the data storage for the Redis server. +$table = new Table(1024); +$table->column('value', Table::TYPE_STRING, 64); +$table->create(); -// We use an array as the data storage for the Redis server. -$server->data = []; // @phpstan-ignore property.notFound +$server = new Server('0.0.0.0', 6379); -$server->setHandler('SET', function (int $fd, array $data) use ($server) { - $server->data[$data[0]] = $data[1]; +$server->setHandler('SET', function (int $fd, array $data) use ($server, $table) { + $table->set($data[0], ['value' => $data[1]]); $server->send($fd, Server::format(Server::STATUS, 'OK')); }); -$server->setHandler('GET', function (int $fd, array $data) use ($server) { +$server->setHandler('GET', function (int $fd, array $data) use ($server, $table) { $key = $data[0]; - if (array_key_exists($key, $server->data)) { - $server->send($fd, Server::format(Server::STRING, $server->data[$key])); + if ($table->exist($key)) { + $server->send($fd, Server::format(Server::STRING, $table->get($key)['value'])); // @phpstan-ignore offsetAccess.nonOffsetAccessible } else { $server->send($fd, Server::format(Server::NIL)); }