From 410397169104ae836a57092405467542808e8810 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 16 Sep 2024 11:47:52 +0800 Subject: [PATCH 1/8] replace sdk --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 45f679f..2cec618 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^8.0", - "dew-serverless/tablestore-php": "^1.1" + "dew-serverless/acs-sdk-php": "^0.2.0" }, "require-dev": { "orchestra/testbench": "^7.37|^8.17", From 45394b8f3610f1b5dd824b1005202072db238143 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 16 Sep 2024 11:48:58 +0800 Subject: [PATCH 2/8] sort packages --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 2cec618..6e1f66d 100644 --- a/composer.json +++ b/composer.json @@ -57,5 +57,8 @@ "@lint", "@test:integration" ] + }, + "config": { + "sort-packages": true } } From 375f09c542152d78189acf99edf115eff635ebf1 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 16 Sep 2024 19:03:27 +0800 Subject: [PATCH 3/8] install google/protobuf --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6e1f66d..5015039 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ ], "require": { "php": "^8.0", - "dew-serverless/acs-sdk-php": "^0.2.0" + "dew-serverless/acs-sdk-php": "^0.2.0", + "google/protobuf": "^4.0" }, "require-dev": { "orchestra/testbench": "^7.37|^8.17", From 58d231cd0d53a8c698703c1c7f0e6b97950e47e4 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 16 Sep 2024 19:32:07 +0800 Subject: [PATCH 4/8] install guzzle adapter on development --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5015039..59b8881 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,11 @@ "google/protobuf": "^4.0" }, "require-dev": { + "laravel/pint": "^1.0", "orchestra/testbench": "^7.37|^8.17", + "php-http/guzzle7-adapter": "^1.0", "phpstan/phpstan": "^1.10", "phpstan/phpstan-strict-rules": "^1.5", - "laravel/pint": "^1.0", "rector/rector": "^0.18.12" }, "autoload": { From 6fbe145c0c903f0050155ebca2bee9cac19ab3b9 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 16 Sep 2024 20:57:23 +0800 Subject: [PATCH 5/8] update code with new sdk --- src/TablestoreServiceProvider.php | 23 +++++------ src/TablestoreStore.php | 63 +++++++++++++++++-------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/src/TablestoreServiceProvider.php b/src/TablestoreServiceProvider.php index 400f1f9..ee9b543 100644 --- a/src/TablestoreServiceProvider.php +++ b/src/TablestoreServiceProvider.php @@ -4,7 +4,7 @@ namespace Dew\TablestoreDriver; -use Dew\Tablestore\Tablestore; +use Dew\Acs\Tablestore\TablestoreInstance; use Illuminate\Support\Facades\Cache; use Illuminate\Support\ServiceProvider; @@ -29,18 +29,15 @@ public function register() private function registerCacheDriver(): void { Cache::extend('tablestore', function ($app, $config) { - $client = new Tablestore( - $config['key'], $config['secret'], - $config['endpoint'], $config['instance'] ?? null - ); - - if (isset($config['token'])) { - $client->tokenUsing($config['token']); - } - - if (isset($config['http'])) { - $client->optionsUsing($config['http']); - } + $client = new TablestoreInstance([ + 'credentials' => [ + 'key' => $config['key'], + 'secret' => $config['secret'], + 'token' => $config['token'] ?? null, + ], + 'instance' => $config['instance'] ?? null, + 'endpoint' => $config['endpoint'], + ]); return Cache::repository( new TablestoreStore( diff --git a/src/TablestoreStore.php b/src/TablestoreStore.php index 7bcb9b1..a1f6014 100644 --- a/src/TablestoreStore.php +++ b/src/TablestoreStore.php @@ -4,21 +4,21 @@ namespace Dew\TablestoreDriver; -use Dew\Tablestore\Attribute; -use Dew\Tablestore\Exceptions\TablestoreException; -use Dew\Tablestore\PlainbufferWriter; -use Dew\Tablestore\PrimaryKey; -use Dew\Tablestore\Responses\RowDecodableResponse; -use Dew\Tablestore\Tablestore; +use Dew\Acs\Tablestore\Attribute; +use Dew\Acs\Tablestore\InstanceException; +use Dew\Acs\Tablestore\Messages\ComparatorType; +use Dew\Acs\Tablestore\Messages\Filter; +use Dew\Acs\Tablestore\Messages\FilterType; +use Dew\Acs\Tablestore\Messages\SingleColumnValueFilter; +use Dew\Acs\Tablestore\Plainbuf; +use Dew\Acs\Tablestore\PlainBufferWriter; +use Dew\Acs\Tablestore\PrimaryKey; +use Dew\Acs\Tablestore\TablestoreInstance; use Illuminate\Contracts\Cache\LockProvider; use Illuminate\Contracts\Cache\Store; use Illuminate\Support\Carbon; use Illuminate\Support\InteractsWithTime; use InvalidArgumentException; -use Protos\ComparatorType; -use Protos\Filter; -use Protos\FilterType; -use Protos\SingleColumnValueFilter; use RuntimeException; final class TablestoreStore implements LockProvider, Store @@ -34,7 +34,7 @@ final class TablestoreStore implements LockProvider, Store * Create a Tablestore cache store. */ public function __construct( - protected Tablestore $tablestore, + protected TablestoreInstance $tablestore, protected string $table, protected string $keyAttribute = 'key', protected string $valueAttribute = 'value', @@ -52,16 +52,19 @@ public function __construct( */ public function get($key) { - $item = $this->tablestore->table($this->table) + $buffer = $this->tablestore->table($this->table) ->whereKey($this->keyAttribute, $this->prefix.$key) ->where($this->expirationAttribute, '>', Carbon::now()->getTimestamp()) - ->get()->getDecodedRow(); + ->get() + ->getRow(); - if ($item === null) { + if ($buffer === '') { return; } - /** @var \Dew\Tablestore\Contracts\HasValue[] */ + $item = Plainbuf::decode($buffer); + + /** @var \Dew\Acs\Tablestore\Cells\HasValue[] */ $values = $item[$this->valueAttribute] ?? []; return isset($values[0]) ? $this->unserialize($values[0]->value()) : null; @@ -95,23 +98,25 @@ public function many(array $keys) $result = array_fill_keys($keys, null); - /** @var \Protos\TableInBatchGetRowResponse[] */ + /** @var \Dew\Acs\Tablestore\Messages\TableInBatchGetRowResponse[] */ $tables = $response->getTables(); - /** @var \Protos\RowInBatchGetRowResponse[] */ + /** @var \Dew\Acs\Tablestore\Messages\RowInBatchGetRowResponse[] */ $rows = $tables[0]->getRows(); foreach ($rows as $row) { - $item = (new RowDecodableResponse($row))->getDecodedRow(); + $buffer = $row->getRow(); - if ($item === null) { + if ($buffer === '') { continue; } - /** @var \Dew\Tablestore\Cells\StringPrimaryKey */ + $item = Plainbuf::decode($buffer); + + /** @var \Dew\Acs\Tablestore\Cells\StringPrimaryKey */ $key = $item[$this->keyAttribute]; - /** @var \Dew\Tablestore\Contracts\HasValue[] */ + /** @var \Dew\Acs\Tablestore\Cells\HasValue[] */ $values = $item[$this->valueAttribute] ?? []; if (isset($values[0])) { @@ -183,7 +188,7 @@ public function add($key, $value, $seconds) { try { Attribute::integer($this->expirationAttribute, Carbon::now()->getTimestamp()) - ->toFormattedValue($now = new PlainbufferWriter); + ->toFormattedValue($now = new PlainBufferWriter); // Include only items that do not exist or that have expired // expression: expiration <= now @@ -205,8 +210,8 @@ public function add($key, $value, $seconds) Attribute::createFromValue($this->valueAttribute, $this->serialize($value)), Attribute::integer($this->expirationAttribute, $this->toTimestamp($seconds)), ]); - } catch (TablestoreException $e) { - if ($e->getError()->getCode() === 'OTSConditionCheckFail') { + } catch (InstanceException $e) { + if ($e->getError()?->getCode() === 'OTSConditionCheckFail') { return false; } @@ -235,8 +240,8 @@ public function increment($key, $value = 1) ]); return true; - } catch (TablestoreException $e) { - if ($e->getError()->getCode() === 'OTSConditionCheckFail') { + } catch (InstanceException $e) { + if ($e->getError()?->getCode() === 'OTSConditionCheckFail') { return false; } @@ -263,8 +268,8 @@ public function decrement($key, $value = 1) ]); return true; - } catch (TablestoreException $e) { - if ($e->getError()->getCode() === 'OTSConditionCheckFail') { + } catch (InstanceException $e) { + if ($e->getError()?->getCode() === 'OTSConditionCheckFail') { return false; } @@ -399,7 +404,7 @@ private function toTimestamp(int $seconds): int /** * The underlying Tablestore client. */ - public function getClient(): Tablestore + public function getClient(): TablestoreInstance { return $this->tablestore; } From c81cd31f597311fef1eba6cbce4d815a8f1965ee Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Wed, 18 Sep 2024 20:53:08 +0800 Subject: [PATCH 6/8] laravel 11 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 59b8881..25b86c6 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require-dev": { "laravel/pint": "^1.0", - "orchestra/testbench": "^7.37|^8.17", + "orchestra/testbench": "^7.0|^8.0|^9.0", "php-http/guzzle7-adapter": "^1.0", "phpstan/phpstan": "^1.10", "phpstan/phpstan-strict-rules": "^1.5", From 6f7b176908849ca0a9e678b88b0b4641dd654201 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Wed, 18 Sep 2024 20:53:32 +0800 Subject: [PATCH 7/8] drops PHP 8.0 and 8.1 --- .github/workflows/test.yaml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1708dcb..ce4b74a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - php: ['8.0', '8.1', '8.2', '8.3'] + php: ['8.2', '8.3'] dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} diff --git a/composer.json b/composer.json index 25b86c6..fc4c639 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.2", "dew-serverless/acs-sdk-php": "^0.2.0", "google/protobuf": "^4.0" }, From 2e544122c132c2ba476f41542dbf241d9a74b9a8 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Wed, 18 Sep 2024 20:58:50 +0800 Subject: [PATCH 8/8] remove last empty line --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ce4b74a..dbd5354 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -59,4 +59,3 @@ jobs: ACS_ACCESS_KEY_SECRET: ${{ secrets.ACS_ACCESS_KEY_SECRET }} TABLESTORE_ENDPOINT: ${{ secrets.TABLESTORE_ENDPOINT }} TABLESTORE_TABLE: ${{ secrets.TABLESTORE_TABLE }} -