Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Throttr\SDK\Responses\InfoResponse;
use Throttr\SDK\Responses\ListResponse;
use Throttr\SDK\Responses\QueryResponse;
use Throttr\SDK\Responses\StatResponse;
use Throttr\SDK\Responses\StatsResponse;
use Throttr\SDK\Responses\StatusResponse;

Expand Down Expand Up @@ -172,12 +173,14 @@ private function processResponses(): void

while (!empty($pendingOperations)) {
$operation = $pendingOperations[0];

$response = match ($operation) {
RequestType::INSERT, RequestType::UPDATE, RequestType::PURGE, RequestType::SET => StatusResponse::fromBytes($buffer, $this->size),
RequestType::QUERY => QueryResponse::fromBytes($buffer, $this->size),
RequestType::GET => GetResponse::fromBytes($buffer, $this->size),
RequestType::LIST => ListResponse::fromBytes($buffer, $this->size),
RequestType::INFO => InfoResponse::fromBytes($buffer, $this->size),
RequestType::STAT => StatResponse::fromBytes($buffer, $this->size),
RequestType::STATS => StatsResponse::fromBytes($buffer, $this->size),
};

Expand Down
15 changes: 15 additions & 0 deletions src/Requests/BaseRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Contracts\ShouldDefineSerialization;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/GetRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/InfoRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/InsertRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/ListRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/PurgeRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/QueryRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/SetRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
58 changes: 58 additions & 0 deletions src/Requests/StatRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
use Throttr\SDK\Enum\ValueSize;

/**
* Stat request
*/
class StatRequest extends BaseRequest
{
/**
* Type
*
* @var RequestType
*/
public RequestType $type = RequestType::STAT;

/**
* Constructor
*
* @param string $key
*/
public function __construct(
public string $key
)
{
}

/**
* To bytes
*
* @param ValueSize $size
* @return string
*/
public function toBytes(ValueSize $size): string
{
return pack(static::pack(ValueSize::UINT8), $this->type->value) .
pack(static::pack(ValueSize::UINT8), strlen($this->key)) .
$this->key;
}
}
15 changes: 15 additions & 0 deletions src/Requests/StatsRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
Expand Down
15 changes: 15 additions & 0 deletions src/Requests/UpdateRequest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\AttributeType;
Expand Down
15 changes: 15 additions & 0 deletions src/Responses/GetResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Responses;

use Throttr\SDK\Enum\TTLType;
Expand Down
15 changes: 15 additions & 0 deletions src/Responses/IResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Responses;

use Throttr\SDK\Enum\ValueSize;
Expand Down
15 changes: 15 additions & 0 deletions src/Responses/InfoResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Responses;

use Throttr\SDK\Enum\KeyType;
Expand Down
15 changes: 15 additions & 0 deletions src/Responses/ListResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Responses;

use Throttr\SDK\Enum\KeyType;
Expand Down
15 changes: 15 additions & 0 deletions src/Responses/QueryResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Responses;

use Throttr\SDK\Enum\TTLType;
Expand Down
Loading